diff options
author | Robin Appelman <robin@icewind.nl> | 2020-02-16 01:45:47 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2020-04-09 12:50:55 +0200 |
commit | 5cd12cd7c39c2ea156ab35266c9359cdd0f4c070 (patch) | |
tree | 47c65715b84db981b59ef3247dbc456ad32e54dc /lib/private/PreviewManager.php | |
parent | 981278a666370ce40d144ea8d7783e712605c1c0 (diff) | |
download | nextcloud-server-5cd12cd7c39c2ea156ab35266c9359cdd0f4c070.tar.gz nextcloud-server-5cd12cd7c39c2ea156ab35266c9359cdd0f4c070.zip |
allow generating multiple preview sizes for a single file at once
this saves having to do some of the overhead multiple times
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/PreviewManager.php')
-rw-r--r-- | lib/private/PreviewManager.php | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/lib/private/PreviewManager.php b/lib/private/PreviewManager.php index 652a442deec..e50b43a51d2 100644 --- a/lib/private/PreviewManager.php +++ b/lib/private/PreviewManager.php @@ -151,6 +151,22 @@ class PreviewManager implements IPreview { return !empty($this->providers); } + private function getGenerator(): Generator { + if ($this->generator === null) { + $this->generator = new Generator( + $this->config, + $this, + $this->appData, + new GeneratorHelper( + $this->rootFolder, + $this->config + ), + $this->eventDispatcher + ); + } + return $this->generator; + } + /** * Returns a preview of a file * @@ -169,20 +185,22 @@ class PreviewManager implements IPreview { * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 */ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { - if ($this->generator === null) { - $this->generator = new Generator( - $this->config, - $this, - $this->appData, - new GeneratorHelper( - $this->rootFolder, - $this->config - ), - $this->eventDispatcher - ); - } + return $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType); + } - return $this->generator->getPreview($file, $width, $height, $crop, $mode, $mimeType); + /** + * Generates previews of a file + * + * @param File $file + * @param array $specifications + * @param string $mimeType + * @return ISimpleFile the last preview that was generated + * @throws NotFoundException + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) + * @since 19.0.0 + */ + public function generatePreviews(File $file, array $specifications, $mimeType = null) { + return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType); } /** |