PreviewService

Extends \OCA\Gallery\Service\Service

Generates previews

package

OCA\Gallery\Service

Methods

Constructor

__construct(string $appName, \OCA\Gallery\Environment\Environment $environment, \OCP\ILogger $logger) 
inherited

Arguments

$appName

string

$logger

\OCP\ILogger

Returns an array containing everything needed by the client to be able to display a preview

createPreview(\OCP\Files\File $file, integer $maxX, integer $maxY, boolean $keepAspect = true, boolean $base64Encode = false) : array
  • fileid: the file's ID
    • mimetype: the file's media type
    • preview: the preview's content

Example logger $this->logger->debug( "[PreviewService] Path : {path} / mime: {mimetype} / fileid: {fileid}", [ 'path' => $preview['data']['path'], 'mimetype' => $preview['data']['mimetype'], 'fileid' => $preview['fileid'] ] );

todo

Get the max size from the settings

Throws
\OCA\Gallery\Service\InternalServerErrorServiceException

Arguments

$file

\OCP\Files\File

$maxX

integer

asked width for the preview

$maxY

integer

asked height for the preview

$keepAspect

boolean

$base64Encode

boolean

Response

array

<string,\OC_Image|string>|false preview data

Returns base64 encoded data of a preview

encode(\OC_Image|string $previewData) : string
inherited

Using base64_encode for files which are downloaded (cached Thumbnails, SVG, GIFs) and using __toStrings for the previews which are instances of \OC_Image

Arguments

$previewData

\OC_Image|string

Response

string

Returns the file matching the given ID

getFile(integer $nodeId) : \OCP\Files\Node
inherited
Throws
\OCA\Gallery\Service\NotFoundServiceException

Arguments

$nodeId

integer

ID of the resource to locate

Response

\OCP\Files\Node

Returns the node matching the given ID

getNode(integer $nodeId) : \OCP\Files\Node
inherited
Throws
\OCA\Gallery\Service\NotFoundServiceException

Arguments

$nodeId

integer

ID of the resource to locate

Response

\OCP\Files\Node

Determines if we can read the content of the file and returns a file pointer resource

isFileReadable(\OCP\Files\File $file) : resource

We can't use something like $node->isReadable() as it's too unreliable Some storage classes just check for the presence of the file

Throws
\OCA\Gallery\Service\InternalServerErrorServiceException

Arguments

$file

\OCP\Files\File

Response

resource

Tests if a GIF is animated

isGifAnimated(\OCP\Files\File $file) : boolean

An animated gif contains multiple "frames", with each frame having a header made up of:

  • a static 4-byte sequence (\x00\x21\xF9\x04)
  • 4 variable bytes
  • a static 2-byte sequence (\x00\x2C) (Photoshop uses \x00\x21)

We read through the file until we reach the end of the file, or we've found at least 2 frame headers

link

http://php.net/manual/en/function.imagecreatefromgif.php#104473

Arguments

$file

\OCP\Files\File

Response

boolean

Decides if we should download the GIF or generate a preview

isGifPreviewRequired(\OCP\Files\File $file, boolean $animatedPreview) : boolean

GIFs are downloaded if they're animated and we want to show animations

Arguments

$file

\OCP\Files\File

$animatedPreview

boolean

Response

boolean

Returns true if the passed mime type is supported

isMimeSupported(string $mimeType = '*') : boolean

In case of a failure, we just return that the media type is not supported

Arguments

$mimeType

string

Response

boolean

Decides if we should download the file instead of generating a preview

isPreviewRequired(\OCP\Files\File $file, boolean $animatedPreview) : boolean

Arguments

$file

\OCP\Files\File

$animatedPreview

boolean

Response

boolean

Decides if we should download the SVG or generate a preview

isSvgPreviewRequired() : boolean

SVGs are downloaded if the SVG converter is disabled Files of any media type are downloaded if requested by the client

Response

boolean

Makes extra sure that we can actually do something with the file

validateNode(\OCP\Files\Node $node) 
inherited
Throws
\OCA\Gallery\Service\NotFoundServiceException

Arguments

$node

\OCP\Files\Node

Properties

previewManager

previewManager : \OCA\Gallery\Preview\Preview

appName

appName : string
inherited
var

Type(s)

string

environment

environment : \OCA\Gallery\Environment\Environment
inherited

logger

logger : \OCP\ILogger
inherited
var

Type(s)

\OCP\ILogger