3

I am using Drupal 6 with the CCK ImageField module. By default, it outputs the height and width of the image as attributes of the tag. For my current project, I'd like to be able to override those with CSS. I have not been able to determine which theme function adds those attributes.

Which functions/templates do I need to override to remove those tags?

1
  • After searching around for a bit I gotta admit I'm stumped! here is some interesting material on the subject but nothing definite: drupal.org/node/173880 I guess if you get desperate enough you could just remove the attributes with javascript ;)
    – Alex Weber
    Apr 19 '11 at 18:17
4

The attributes are there for browser performance reasons. Overriding them with CSS is still possible. If you want to specify the width, set the height to auto, or vice-versa.

4
  • I'm pretty sure that inline attribute tags override CSS but I could be wrong :)
    – Alex Weber
    Apr 19 '11 at 19:41
  • 1
    Try it on any image with firebug, you'll see that it works. Even the stackexchange avatars! Apr 20 '11 at 13:36
  • 1
    Inline css, like <img style="width:100px; height:100px;"> would override other CSS, but the height and width attributes are overridden fine. Apr 21 '11 at 1:57
  • sounds about right! :)
    – Alex Weber
    Apr 21 '11 at 3:47
1

I found the answer I was looking for, although it required knowing I was also using ImageCache. I needed to override theme_imagecache() in template.php:

function mytheme_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  // Overrode the default here to get ride of height and width attributes.

  // Check is_null() so people can intentionally pass an empty array of
  // to override the defaults completely.
  if (is_null($attributes)) {
    $attributes = array('class' => 'imagecache imagecache-'. $presetname);
  }

  $attributes = drupal_attributes($attributes);
  $imagecache_url = imagecache_create_url($presetname, $path);
  return '<img src="'. $imagecache_url .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
}

That said, Tim's answer is easier and likely would have worked just as well or better.

1
  • sounds good, if its resolved just make sure to pick an answer! :)
    – Alex Weber
    Apr 21 '11 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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