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.


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

4 Answers 4


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.

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.


I resolved this by adding the dimensions with CSS.

  • 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
    May 30, 2014 at 17:05

You can also try removing all the attributes with:

function hook_preprocess_image(&$variables) {
  foreach (array('width', 'height') as $key) {

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) {

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.