Thumbnail formatter does not set image width and height

Created on 21 April 2019, over 5 years ago
Updated 25 July 2023, over 1 year ago

Hi there. While using this module I noticed that the Thumbnail formatter doesn't set the image width and height, which is a bit unexpected as core usually does, including on image style derivatives. I've written my own replacement formatter that does that (I have some template stuff that reserves space before an image has loaded equal to the aspect ratio of the image so that the page doesn't shift, but this requires knowing the width and height for the ratio) and other stuff, so if there's interest in getting this added into this module, I can try to put together a patch.

Feature request
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

🇨🇦Canada ambient.impact Toronto

Live updates comments and jobs are added and updated live.
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.

  • 🇫🇷France prudloff Lille

    I would love to write a patch for this but since this issue was closed as won't fix, we use a preprocess_field that does this:

        foreach ($variables['items'] as $i => $item) {
          if (isset($item['content']['#theme']) && $item['content']['#theme'] == 'image_style') {
            $image = \Drupal::service('image.factory')
              ->get($item['content']['#uri']);
            $variables['items'][$i]['content']['#width'] = $image->getWidth();
            $variables['items'][$i]['content']['#height'] = $image->getHeight();
          }
        }
    
Production build 0.71.5 2024