Drupal: Render Images with Style

Dev

Drupal: Render Images with Style

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:

More About the Author

Chris Armstrong

Multimedia Manager
Drupal Quick Tip: Auto “node/nid” Paths from Alias in Menus “In learning you will teach, and in teaching you will learn.” Words spoken by (or, at least, attributed to) the great Phil ...
Quick Tutorial on Overriding Drupal Views using Templates Scott and I were recently invited to Oklahoma State University to provide Drupal training for their web admins. Drupal has been on the ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

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