From 3b50506aa035bfcffa3c38ea675b2182ee726fb1 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 6 Jan 2017 18:44:05 +1300 Subject: [PATCH] Fail manipulateImage() without image resource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes a manipulation can’t be carried out, either because the backend isn’t available, or because there isn’t enough PHP memory available. In these cases, $backend->getImageResource() will be set to NULL. This should be picked up by manipulateImage(), to avoid passing an invalid backend into the $callback provided. The specific case this solves is calling Image->FitMax() on large images: $resizedImage = $originalImage->FitMax(, ) This will have $resizedImage==$originalImage if the image is smaller than the targeted dimensions, but with this fix $resizedImage==NULL if the image is too large to be resized. Which gives custom code the ability to determine which of the two should be used, for example choosing not to pass the original large image URL to the client since it wouldn’t be considered a “thumbnail” size. --- src/Assets/ImageManipulation.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Assets/ImageManipulation.php b/src/Assets/ImageManipulation.php index 7a83de63a..7e0b8fa9b 100644 --- a/src/Assets/ImageManipulation.php +++ b/src/Assets/ImageManipulation.php @@ -725,7 +725,9 @@ trait ImageManipulation function (AssetStore $store, $filename, $hash, $variant) use ($callback) { /** @var Image_Backend $backend */ $backend = $this->getImageBackend(); - if (!$backend) { + + // If backend isn't available + if (!$backend || !$backend->getImageResource()) { return null; } $backend = $callback($backend);