image scale does not work when current dimensions are unknown

Created on 30 April 2012, about 12 years ago
Updated 14 February 2023, over 1 year ago

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 ✨ Combine image scale and resize effects and add preserve aspect ratio option to scale Needs work 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.

πŸ› Bug report
Status

Needs work

Version

9.5

Component
Image systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡«πŸ‡·France fietserwin Le Mont-Dore

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Emil Stoianov

    This 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

        $image = \Drupal::service('image.factory')->get(DRUPAL_ROOT . $variables['img_element']['#uri']);
        $width = $image->getWidth();
    

    Which also has it empty.

Production build 0.69.0 2024