PreviewManager

class OC\PreviewManager
Source:lib/private/PreviewManager.php#46
Implements:OCP\IPreview

Properties

protected static property OC\PreviewManager::$config
Source:lib/private/PreviewManager.php#48
Type:\OCP\IConfig
protected static property OC\PreviewManager::$rootFolder
Source:lib/private/PreviewManager.php#51
Type:\OCP\Files\IRootFolder
protected static property OC\PreviewManager::$appData
Source:lib/private/PreviewManager.php#54
Type:\OCP\Files\IAppData
protected static property OC\PreviewManager::$eventDispatcher
Source:lib/private/PreviewManager.php#57
Type:\Symfony\Component\EventDispatcher\EventDispatcherInterface
protected static property OC\PreviewManager::$providerListDirty
Source:lib/private/PreviewManager.php#66
Type:bool
protected static property OC\PreviewManager::$registeredCoreProviders
Source:lib/private/PreviewManager.php#69
Type:bool
protected static property OC\PreviewManager::$providers
Source:lib/private/PreviewManager.php#72
Type:array
protected static property OC\PreviewManager::$mimeTypeSupportMap
Source:lib/private/PreviewManager.php#75
Type:array mime type => support status
protected static property OC\PreviewManager::$defaultProviders
Source:lib/private/PreviewManager.php#78
Type:array
protected static property OC\PreviewManager::$userId
Source:lib/private/PreviewManager.php#81
Type:string

Methods

public OC\PreviewManager::__construct($config, $rootFolder, $appData, $eventDispatcher, $helper, $userId)
PreviewManager constructor.
Source:

lib/private/PreviewManager.php#92

Parameters:
public OC\PreviewManager::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 or \OCP\Preview\IProviderV2
Source:

lib/private/PreviewManager.php#116

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

void

public OC\PreviewManager::getProviders()
Get all providers
Source:lib/private/PreviewManager.php#132
Returns:array
public OC\PreviewManager::hasProviders()
Does the manager have any providers
Source:lib/private/PreviewManager.php#151
Returns:bool
public OC\PreviewManager::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/private/PreviewManager.php#189

Parameters:
  • $file (OCP\Files\File)
  • $width (int)
  • $height (int)
  • $crop (bool)
  • $mode (string)
  • $mimeType (string)
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 OC\PreviewManager::generatePreviews($file, $specifications, $mimeType=null)
Generates previews of a file
Source:

lib/private/PreviewManager.php#204

Parameters:
Returns:

\OCP\Files\SimpleFS\ISimpleFile the last preview that was generated

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:

19.0.0

public OC\PreviewManager::isMimeSupported($mimeType=*)
returns true if the passed mime type is supported
Source:

lib/private/PreviewManager.php#214

Parameters:
  • $mimeType (string)
Returns:

bool

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

lib/private/PreviewManager.php#241

Parameters:
Returns:

bool

protected OC\PreviewManager::getEnabledDefaultProvider()
List of enabled default providers
The following providers are enabled by default:
- OC\Preview\PNG
- OC\Preview\JPEG
- OC\Preview\GIF
- OC\Preview\BMP
- OC\Preview\HEIC
- OC\Preview\XBitmap
- OC\Preview\MarkDown
- OC\Preview\MP3
- OC\Preview\TXT

The following providers are disabled by default due to performance or privacy concerns:
- OC\Preview\Font
- OC\Preview\Illustrator
- OC\Preview\Movie
- OC\Preview\MSOfficeDoc
- OC\Preview\MSOffice2003
- OC\Preview\MSOffice2007
- OC\Preview\OpenDocument
- OC\Preview\PDF
- OC\Preview\Photoshop
- OC\Preview\Postscript
- OC\Preview\StarOffice
- OC\Preview\SVG
- OC\Preview\TIFF
Source:lib/private/PreviewManager.php#304
Returns:array
protected OC\PreviewManager::registerCoreProvider($class, $mimeType, $options=[])
Register the default providers (if enabled)
Source:

lib/private/PreviewManager.php#340

Parameters:
  • $class (string)
  • $mimeType (string)
protected OC\PreviewManager::registerCoreProviders()
Register the default providers (if enabled)
Source:lib/private/PreviewManager.php#351