Fail manipulateImage() without image resource

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(<width>, <height>)
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.
This commit is contained in:
Ingo Schommer 2017-01-06 18:44:05 +13:00
parent fcb511b1c0
commit 3b50506aa0

View File

@ -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);