We offer affordable conversion services to convert from PSD to Drupal.
Submit your own design composition to us to start building your Drupal site now.
Submit your brief for custom modules that you'd like us to build.

Drupal 7 - theme_imagecache replacement

Article by duckz
created at 15. Jan, 2011

Drupal 7 integrate the notorious Drupal 6 imagecache module in its core, so without installing additional modules, we can resize and cache images in Drupal 7 easily.

While the core image module provides GUI to create the "style" ("presets" in Drupal 6) and field module provides GUI for selecting which "style" is going to be used for displaying the image, how about if we need to do it via code like in node.tpl.php?

If you remember Drupal 6 imagecache module, we used to invoke :

<?php theme('imagecache''preset''imagepath''alt''title'); ?>

to display the resized and cached image. Now in Drupal 7 we have similar way to do it but slightly different function to invoke :

<?php
theme
('image_style', array('style_name' => 'slider_content''path' => 'image path''alt' => 'image alt''title' => 'image title''width' => 'some width''height' => 'some height')));
?>

and you will get the same result as in drupal 6.

Got better way to do this? post it in your comment

3 comments
Nicholas (not verified) say:
Mon, 10/10/2011 - 09:52
Nicholas's picture

thanks for the tip! works perfect for me :)

duckz say:
Thu, 01/20/2011 - 12:37
duckz's picture

Ahh yes you're right, It is fixed now :)

Anonymous (not verified) say:
Wed, 01/19/2011 - 16:19
Anonymous's picture

Hi,
I think there is a mistake... Should be
theme('image_style',

Post new comment

The content of this field is kept private and will not be shown publicly.
Image CAPTCHA
Enter the characters shown in the image.
To prevent automated spam submissions leave this field empty.