Drupal 7 Theme Image Thumbnails

In Drupal 7 there is a theme('image_style') which is similar to theme('imagecache')

<?php
$hero_image = array(
  'style_name' => 'case_study_teaser',
  'path' => $image['uri'],
  'width' => '',
  'height' => '',
  'alt' => $image['alt'],
  'title' => $image['title'],
  );
print theme('image_style',$hero_image);
?>

There is also a very handy little function in Drupal 7.

<?php
$img_url = 'public://myimagefolder/imgfilename.jpg';  // the orig image uri
$style = 'thumbnail';  // or any other custom image style you've created via /admin/config/media/image-styles
?>
<img src="<?php print image_style_url($style, $img_url) ?>>

The image_style_url() function takes the URI and converts into the relevant URL for the image style provided. Note, you need to use public:// rather than the base url of your site for this function to work.

The great thing is that if the image hasn't yet been created then Drupal does it automatically!




Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
Bg