Nextcloud PHP API (stable19)

IPreview

This class provides functions to render and show thumbnails and previews of files

Tags
since
6.0.0

Table of Contents

EVENT  = self::class . ':' . 'PreviewRequested'
MODE_COVER  = 'cover'
MODE_FILL  = 'fill'
generatePreviews()  : ISimpleFile
Generates previews of a file
getPreview()  : ISimpleFile
Returns a preview of a file
getProviders()  : array
Get all providers
hasProviders()  : bool
Does the manager have any providers
isAvailable()  : bool
Check if a preview can be generated for a file
isMimeSupported()  : bool
Returns true if the passed mime type is supported
registerProvider()  : void
In order to improve lazy loading a closure can be registered which will be called in case preview providers are actually requested

Constants

EVENT

public mixed EVENT = self::class . ':' . 'PreviewRequested'
Tags
since
9.2.0

MODE_COVER

public mixed MODE_COVER = 'cover'

MODE_FILL

public mixed MODE_FILL = 'fill'

Methods

generatePreviews()

Generates previews of a file

public generatePreviews(File $file, array $specifications[, string $mimeType = null ]) : ISimpleFile
Parameters
$file : File
$specifications : array
$mimeType : string = null
Tags
throws
NotFoundException
throws
InvalidArgumentException

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

since
19.0.0
Return values
ISimpleFile

the last preview that was generated

getPreview()

Returns a preview of a file

public getPreview(File $file[, int $width = -1 ][, int $height = -1 ][, bool $crop = false ][, string $mode = IPreview::MODE_FILL ][, string $mimeType = null ]) : ISimpleFile

The cache is searched first and if nothing usable was found then a preview is generated by one of the providers

Parameters
$file : File
$width : int = -1
$height : int = -1
$crop : bool = false
$mode : string = IPreview::MODE_FILL
$mimeType : string = null

To force a given mimetype for the file (files_versions needs this)

Tags
throws
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
Return values
ISimpleFile

getProviders()

Get all providers

public getProviders() : array
Tags
since
8.1.0
Return values
array

hasProviders()

Does the manager have any providers

public hasProviders() : bool
Tags
since
8.1.0
Return values
bool

isAvailable()

Check if a preview can be generated for a file

public isAvailable(FileInfo $file) : bool
Parameters
$file : FileInfo
Tags
since
8.0.0
Return values
bool

isMimeSupported()

Returns true if the passed mime type is supported

public isMimeSupported([string $mimeType = '*' ]) : bool
Parameters
$mimeType : string = '*'
Tags
since
6.0.0
Return values
bool

registerProvider()

In order to improve lazy loading a closure can be registered which will be called in case preview providers are actually requested

public registerProvider(string $mimeTypeRegex, Closure $callable) : void

$callable has to return an instance of \OCP\Preview\IProvider

Parameters
$mimeTypeRegex : string

Regex with the mime types that are supported by this provider

$callable : Closure
Tags
since
8.1.0

Search results