From a5ad5bf29bdba3aae34473a7fd5114f2ae750be9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Sep 2015 17:10:08 +0200 Subject: [PATCH] Fix preview caching --- lib/private/preview.php | 44 ++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/private/preview.php b/lib/private/preview.php index cd92f15b92..1127048b7f 100644 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -838,19 +838,16 @@ class Preview { $askedHeight = $this->getMaxY(); if ($this->mode === self::MODE_COVER) { - list($scaleWidth, $scaleHeight) = + list($askedWidth, $askedHeight) = $this->applyCover($askedWidth, $askedHeight, $previewWidth, $previewHeight); - } else { - $scaleWidth = $askedWidth; - $scaleHeight = $askedHeight; } /** * Phase 1: If required, adjust boundaries to keep aspect ratio */ if ($this->keepAspect) { - list($scaleWidth, $scaleHeight) = - $this->applyAspectRatio($scaleWidth, $scaleHeight, $previewWidth, $previewHeight); + list($askedWidth, $askedHeight) = + $this->applyAspectRatio($askedWidth, $askedHeight, $previewWidth, $previewHeight); } /** @@ -858,7 +855,7 @@ class Preview { * Takes the scaling ratio into consideration */ list($newPreviewWidth, $newPreviewHeight) = $this->scale( - $image, $scaleWidth, $scaleHeight, $previewWidth, $previewHeight + $image, $askedWidth, $askedHeight, $previewWidth, $previewHeight ); // The preview has been resized and should now have the asked dimensions @@ -870,28 +867,25 @@ class Preview { /** * Phase 3: We're still not there yet, so we're clipping and filling - * to match the asked dimensions if we're not asked to keep aspect ratio + * to match the asked dimensions */ + // It turns out the scaled preview is now too big, so we crop the image + if ($newPreviewWidth >= $askedWidth && $newPreviewHeight >= $askedHeight) { + $this->crop($image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight); + $this->storePreview($fileId, $askedWidth, $askedHeight); - if (!$this->keepAspect) { - // It turns out the scaled preview is now too big, so we crop the image - if ($newPreviewWidth >= $askedWidth && $newPreviewHeight >= $askedHeight) { - $this->crop($image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight); - $this->storePreview($fileId, $askedWidth, $askedHeight); + return; + } - return; - } + // At least one dimension of the scaled preview is too small, + // so we fill the space with a transparent background + if (($newPreviewWidth < $askedWidth || $newPreviewHeight < $askedHeight)) { + $this->cropAndFill( + $image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight + ); + $this->storePreview($fileId, $askedWidth, $askedHeight); - // At least one dimension of the scaled preview is too small, - // so we fill the space with a transparent background - if (($newPreviewWidth < $askedWidth || $newPreviewHeight < $askedHeight)) { - $this->cropAndFill( - $image, $askedWidth, $askedHeight, $newPreviewWidth, $newPreviewHeight - ); - $this->storePreview($fileId, $askedWidth, $askedHeight); - - return; - } + return; } // The preview is smaller, but we can't touch it