0

My site runs now on Drupal 7.9. On the release notes (4th position) it is reported the following note:

Restored height/width attributes on images run through the theme system

That is exactly what I don't want, because my images get distorted.

screenshot

How can I prevent height/width attributes on images run through the theme system?

4 Answers 4

3

History
In Drupal 6, populating width/height attributes caused a filesystem lookup (bad for back-end performance) for every image. This was fixed in #908282: Remove unnecessary I/O from theme_image() by removing the height/width attributes altogether in Drupal 7.

Images without height/width attributes are bad for front-end performance so work was done in Populate HTML image tags with dimension attributes (like D6 imagefield) without re-introducing I/O to add them back.

Answer
So you really want your images to have width/height but obviously not if they get distorted. The update functions for 7.9 were supposed to fix this, did you run update.php after upgrading to 7.9?

If you ran update.php then this might be a bug.

3

I resolved this by adding the dimensions with CSS.

1
  • This also solved it for me. I simply assigned a class to the image tag and assigned a width and height via <style> css at the beginning of the message.
    – EJK
    Commented May 30, 2014 at 17:05
2

You can also try removing all the attributes with:

function hook_preprocess_image(&$variables) {
  foreach (array('width', 'height') as $key) {
    unset($variables[$key]);
  }
}
0

The best way to do it (just like in Drupal 7) is to use hook_preprocess_HOOK().

In your THEME.theme file (where THEME is the name of your theme), define a function as such:

function THEME_preprocess_image(&$variables) {
  unset($variables['attributes']['width']);
  unset($variables['attributes']['height']);
}

Hope it helps. Happy coding!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.