Drupal: Render Images with Style

Drupal: Render Images with Style

Chris Armstrong
//

In Drupal 6, a module called Imagecache allowed developers to create custom styles to dynamically manipulate an image. We typically use Imagecache to scale and crop images to specific dimensions, but Imagecache can rotate images, deal with opacity, add borders, change colors and even change file formats.

With the release of Drupal 7, Imagecache was brought into the core and renamed “Image styles”. With that change (and others dealing with the file system), the code to render the image also changed.

Here’s the Drupal 6 way with Imagecache:

print theme('imagecache', 'imagecache_style_name', 'path/to/image.jpg', 'alt_text', 'title');

Here’s the Drupal 7 way with Image styles:

print theme('image_style', array('style_name' => 'image_style_name', 'path' => 'path/to/image.jpg'))

Your variables will go into the italicized spots.

Imagecache and Image styles also integrates with Views. So if you don’t want to mess with the code, you can always use Views.

Since that was so quick and easy, spend the rest of the time you would’ve been stuck working on that and watch this video of my fellow web dev Scott:

Related

Need Expert Help?

See Our Full Menu of Data Services

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072

×

Love our blog? You should see our emails. Sign up for our newsletter!