Text Size
Sunday, May 20, 2012
Get a look down
General >> Code snippets >> How to use Drupal's imagecache in custom module
Wednesday, 27 July 2011 16:48

How to use Drupal's imagecache in custom module

Written by Nabil Sadki
Rate this item
(0 votes)

You can use imagecache directly in your module, invoke a preset, and apply it on an uploaded image with this code snippet :

1
2
3
4
5
6
7
8
9
10
// $preset: the name of your preset
// $image['filepath']: the path to your file. E.g: sites/default/files/my_picture.jpg
// $alt: the alt of your <img> tag
// $title: the title of your <img> tag
// $attributes: your can add attributes to the <img> tag. E.g: $attributes = array('class' => 'mypic')
//          will add a class 'mypic' to your image.
print theme('imagecache', $preset, $image['filepath'], $alt, $title,  $attributes); 
 
// E.g:
print theme('imagecache', 'my_custom_thumb_preset', 'sites/deafult/files/my_picture.jpg', t('My picture alt'), t('My picture title')); 
Last modified on Wednesday, 27 July 2011 17:07
Nabil Sadki

Nabil Sadki

Hello, I am Nabyl, a Freelance web developer and a joomla addict. I have made many sites using the latter, but also patches for the core of this CMS. I like HipHop culture and world of warcraft. You can find find me on Twitter when i'm free...

Website: www.coins.ma E-mail: This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Add comment



Usefull tricks