IPreview

interface OCP\IPreview
This class provides functions to render and show thumbnails and previews of files
Implemented by:OC\PreviewManager
Source:lib/public/IPreview.php#45

Constants

EVENT = self::class . : . PreviewRequested
Source:lib/public/IPreview.php#50
Since:9.2.0
MODE_FILL = fill
Source:lib/public/IPreview.php#52
MODE_COVER = cover
Source:lib/public/IPreview.php#53

Methods

public OCP\IPreview::registerProvider($mimeTypeRegex, $callable)
In order to improve lazy loading a closure can be registered which will be
called in case preview providers are actually requested
$callable has to return an instance of \OCP\Preview\IProvider
Source:

lib/public/IPreview.php#66

Parameters:
  • $mimeTypeRegex (string) Regex with the mime types that are supported by this provider
  • $callable (Closure)
Returns:

void

Since:

8.1.0

public OCP\IPreview::getProviders()
Get all providers
Source:lib/public/IPreview.php#73
Returns:array
Since:8.1.0
public OCP\IPreview::hasProviders()
Does the manager have any providers
Source:lib/public/IPreview.php#80
Returns:bool
Since:8.1.0
public OCP\IPreview::createPreview($file, $maxX=100, $maxY=75, $scaleUp=false)
Return a preview of a file
Source:

lib/public/IPreview.php#92

Parameters:
  • $file (string) The path to the file where you want a thumbnail from
  • $maxX (int) The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
  • $maxY (int) The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
  • $scaleUp (bool) Scale smaller images up to the thumbnail size or not. Might look ugly
Returns:

\OCP\IImage

Since:

6.0.0

Deprecated:

11 Use getPreview

public OCP\IPreview::getPreview($file, $width=-1, $height=-1, $crop=false, $mode=\OCP\IPreview::MODE_FILL, $mimeType=null)
Returns a preview of a file
The cache is searched first and if nothing usable was found then a preview is
generated by one of the providers
Source:

lib/public/IPreview.php#111

Parameters:
  • $file (OCP\Files\File)
  • $width (int)
  • $height (int)
  • $crop (bool)
  • $mode (string)
  • $mimeType (string) To force a given mimetype for the file (files_versions needs this)
Returns:

\OCP\Files\SimpleFS\ISimpleFile

Throws:

\OCP\Files\NotFoundException

Throws:

\InvalidArgumentException if the preview would be invalid (in case the original image is invalid)

Throws:

\OCP\Files\NotFoundException

Throws:

\InvalidArgumentException if the preview would be invalid (in case the original image is invalid)

Since:

11.0.0 - \InvalidArgumentException was added in 12.0.0

public OCP\IPreview::isMimeSupported($mimeType=*)
Returns true if the passed mime type is supported
Source:

lib/public/IPreview.php#119

Parameters:
  • $mimeType (string)
Returns:

bool

Since:

6.0.0

public OCP\IPreview::isAvailable($file)
Check if a preview can be generated for a file
Source:

lib/public/IPreview.php#128

Parameters:
Returns:

bool

Since:

8.0.0