The image scale effect allows one to scale an image while preserving the aspect ratio. So, only 1 of the new dimensions need to be specified.
The implementation of this effect assumes that as soon as this effect is applied, the current dimensions are known. Subsequently, the arithmetic to preserve aspect ratio is done in non image toolkit specific code and the results are passed to the resize effect.
Though the assumption that intermediate dimensions are known may hold for the GD toolkit that is part of core, it does not hold for the Imagemagick toolkit. The Imagemagick toolkit would just pass the 1 available parameter to the imagemagick processing but cannot do so as the effect is changed into a resize effect before being processed by toolkit specific code.
This error will reveal itself if the scale effect is chained after another effect that cannot compute resulting dimensions, like random rotate.
Issue #524562: Combine image scale and resize effects and add preserve aspect ratio option to scale might (will) be influenced by this patch. But as this is a bug that needs backporting to D7, I filed it as a separate issue.
Comment | File | Size | Author |
---|---|---|---|
#5 | 1554074-5.patch | 25.03 KB | fietserwin |
#3 | 1554074-3.patch | 25.44 KB | fietserwin |
#1 | drupal-1554074-1.patch | 24.98 KB | fietserwin |
Comments
Comment #1
fietserwinPlease find attached a patch that solve the error indicated. Though solving it was not such a big deal, it turned out that quite some tests had to be changed to pass with this patch.
A summary of changes in this patch:
Comment #3
fietserwinOops, I forgot to reset to the remote 8.x branch but reset to my local 8.x branch instead and missed a large file movement/renaming refactoring.
Trying again. Locally I did get some exception about not being permitted to remove a config file, but that's not due to my changes.
Comment #5
fietserwinOne more try, without my local .htaccess changes.
Comment #6
cweagansUpdating tags per http://drupal.org/node/1517250
Comment #7
claudiu.cristeaInteresting but I'm not sure I understood. Looking in the code I saw that the missed dimension is computed before the toolkit is called (with resize). So, when ImageMagick toolkit is called, both dimensions are known and the toolkit is expected to resize. What else?
Comment #8
fietserwin#7: With Imagemagick as toolkit, it may occur that $this->getWidth() and $this->getHeight() return NULL because the width and height in the current transformation process are unknown. this can happen after an autorotate (based on exif data; contrib image effect) or after a random rotate.
For the imagemagick toolkit this is not bad. The convert binary will know the dimensions when actually processing the effects and can scale based on just the scale dimensions (i.e. the effect data).
However, before getting there ImageUtility::scaleDimensions() will fail with a division by zero (NULL/NULL).
Setting to needs work, because a reroll will be needed anyway.
Comment #14
a_grizzli CreditAttribution: a_grizzli commentedThis issue is still a problem, when there is a need to use ImageMagick Toolkit and combine image operations with scaling...
Comment #15
mourad-zitouni CreditAttribution: mourad-zitouni commentedYes I'm having a problem with Image style also
Comment #16
mondrake#14, #15: I am quite sure in Drupal 8 this is no longer a problem, since several steps have been taken to improve dimension calculation at runtime.
Can you confirm? If so, let's move this issue to D7 only.
Comment #17
mourad-zitouni CreditAttribution: mourad-zitouni commentedI tested it today in a local (Apache/2.4.25, PHP 7.2.4) and I'm having an error trying to display an image :
Image scale failed using the gd toolkit on
Comment #25
Emil Stoianov CreditAttribution: Emil Stoianov as a volunteer commentedThis is still an issue in D9.5
Images displayed with a scale effect, in the image style configuration, do not have dimensions displayed in the image tag
Trying to get those in a preprocess function
Which also has it empty.