From 3d1f22f6d8720ff0ed574bc21d32ea2a45a42c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Wed, 6 Apr 2022 18:53:21 +0200 Subject: [PATCH] Generate small preview straight away if Imaginary is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- lib/private/Preview/Generator.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index a770fe3b459c3..cef3fa4039ae7 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -137,9 +137,10 @@ public function generatePreviews(File $file, array $specifications, $mimeType = $previewVersion = $file->getPreviewVersion() . '-'; } + // If imaginary is enabled, and we request a small thumbnail, + // let's not generate the max preview for performance reasons if (count($specifications) === 1 - && (($specifications[0]['width'] === 250 && $specifications[0]['height'] === 250) - || ($specifications[0]['width'] === 150 && $specifications[0]['height'] === 150)) + && ($specifications[0]['width'] <= 256 || $specifications[0]['height'] <= 256) && preg_match(Imaginary::supportedMimeTypes(), $mimeType) && $this->config->getSystemValueString('preview_imaginary_url', 'invalid') !== 'invalid') { $crop = $specifications[0]['crop'] ?? false; @@ -221,6 +222,10 @@ public function generatePreviews(File $file, array $specifications, $mimeType = return $preview; } + /** + * Generate a small image straight away without generating a max preview first + * Preview generated is 256x256 + */ private function getSmallImagePreview(ISimpleFolder $previewFolder, File $file, string $mimeType, string $prefix, bool $crop) { $nodes = $previewFolder->getDirectoryListing();