Dominique De Cooman
Published on Dominique De Cooman (https://dominiquedecooman.com)

Home > Theme image cache function in drupal

Dominique De Cooman
Saturday, May 16, 2009 - 22:59

Used to resize images, scale and crop images. Use it allot.
Install the image cache module. Create a preset and call it with this function.

<?php
example $image 
= theme('imagecache', 'nieuws_teaser', $node->field_image[0]['filepath'], $node->field_image[0]['data']['alt'], $node->field_image[0]['data']['title'], array('description' => $node->field_image[0]['data']['description']));
?>

<?php
@namespace : name of preset
@path : path of image
@alt, title, attributes : html attributes of the img tag
?>

<?php
function theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = NULL) {
  
$attributes = drupal_attributes($attributes);
  
$imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
  return 
'<img src="'. $imagecache_path .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
}
?>


Source URL: https://dominiquedecooman.com/blog/theme-image-cache-function-drupal