From 5cd12cd7c39c2ea156ab35266c9359cdd0f4c070 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 16 Feb 2020 01:45:47 +0100 Subject: 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 --- lib/private/PreviewManager.php | 44 +++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'lib/private/PreviewManager.php') 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); } /** -- cgit v1.2.3