function imageinfo_cache_theme_imagecache in Imageinfo Cache 6
Same name and namespace in other branches
- 6.2 imageinfo_cache.module \imageinfo_cache_theme_imagecache()
Create an image tag for an imagecache derivative
Parameters
$presetname: String with the name of the preset used to generate the derivative image.
$path: String path to the original image you wish to create a derivative image tag for.
$alt: Optional string with alternate text for the img element.
$title: Optional string with title for the img element.
$attributes: Optional drupal_attributes() array. If $attributes is an array then the default imagecache classes will not be set automatically, you must do this manually.
$getsize: If set to TRUE, the image's dimension are fetched and added as width/height attributes.
Return value
HTML img element string.
1 string reference to 'imageinfo_cache_theme_imagecache'
- imageinfo_cache_theme_registry_alter in ./
imageinfo_cache.module - Implementation of hook_theme_registry_alter().
File
- ./
imageinfo_cache.module, line 309 - Cache image info for theme_imagecache & theme_imagefield_image.
Code
function imageinfo_cache_theme_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
// Only run if we are going to get the width and height from the file.
if ($getsize) {
$imagecache_path = imagecache_create_path($presetname, $path);
if ($imagecache_path) {
// Cache ID and cache_get.
$cid = 'imagecache_' . $presetname . '_' . md5($path);
$image = cache_get($cid, 'cache_imageinfo');
// Use cached data if available.
if (!empty($image)) {
$image = $image->data;
if (empty($image) || empty($image['width']) || empty($image['height'])) {
unset($image);
}
if ($image['width'] == 1 || $image['height'] == 1) {
unset($image);
}
}
// Get the width and height from the file if $image was bad.
if (empty($image)) {
$image = image_get_info($imagecache_path);
if (!empty($image) && !empty($image['width']) && !empty($image['height'])) {
$lifetime = variable_get('imageinfo_cache_lifetime', IMAGEINFO_CACHE_LIFETIME);
cache_set($cid, $image, 'cache_imageinfo', time() + $lifetime);
}
}
// If we have the image info then set some variables before calling the
// original theme function.
if (!empty($image) && !empty($image['width']) && !empty($image['height'])) {
// Check is_null() so people can intentionally pass an empty array of
// to override the defaults completely.
if (is_null($attributes)) {
$attributes = array(
'class' => 'imagecache imagecache-' . $presetname,
);
}
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
$getsize = FALSE;
}
}
}
// Run original theme function.
$function = variable_get('imageinfo_cache_theme_imagecache_callback', IMAGEINFO_CACHE_THEME_IMAGECACHE_CALLBACK);
return $function($presetname, $path, $alt, $title, $attributes, $getsize);
}