function imageinfo_cache_theme_imagefield_image in Imageinfo Cache 6.2
Same name and namespace in other branches
- 6 imageinfo_cache.module \imageinfo_cache_theme_imagefield_image()
Caches the image dimensions; passes dimensions to the orginal theme function.
See also
2 string references to 'imageinfo_cache_theme_imagefield_image'
- imageinfo_cache_theme_registry_alter in ./
imageinfo_cache.module - Implements hook_theme_registry_alter().
- imageinfo_cache_uninstall in ./
imageinfo_cache.install - Implementation of hook_uninstall().
File
- ./
imageinfo_cache.module, line 383 - Cache image info for theme_imagecache & theme_imagefield_image.
Code
function imageinfo_cache_theme_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
$file = (array) $file;
if ($getsize) {
// Use cached width and height if available.
if (!empty($file['data']['width']) && !empty($file['data']['height'])) {
$attributes['width'] = $file['data']['width'];
$attributes['height'] = $file['data']['height'];
$getsize = FALSE;
}
else {
// Cache ID and cache_get.
$cid = 'theme_imagefield_' . md5($file['filepath']);
$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 = @getimagesize($file['filepath']);
if (!empty($image)) {
$image['width'] = $image[0];
$image['height'] = $image[1];
$lifetime = variable_get('imageinfo_cache_lifetime', IMAGEINFO_CACHE_LIFETIME);
cache_set($cid, $image, 'cache_imageinfo', time() + $lifetime);
}
}
// Set the width and height.
if (!empty($image) && !empty($image['width']) && !empty($image['height'])) {
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
$getsize = FALSE;
}
}
}
// Run original theme function.
$function = variable_get('imageinfo_cache_theme_imagefield_image_callback', IMAGEINFO_CACHE_THEME_IMAGEFIELD_IMAGE_CALLBACK);
return $function($file, $alt, $title, $attributes, $getsize);
}