Closed (won't fix)
Project:
ImageCache
Version:
6.x-2.0-beta9
Component:
imagecache_image module
Priority:
Minor
Category:
Bug report
Assigned:
Reporter:
Created:
23 Jun 2009 at 09:17 UTC
Updated:
24 May 2012 at 07:53 UTC
When I developed my module, I deleted images by hand, and backup/restore DB very often.
I had a problem, my images don't displayed through theme_imagecache.
I researched code and added check for existents file in folder files/imagecache/_preset_name_.
If file was deleted by any reasons or simply absent, then we rebuild image and put to folder.
function theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = NULL) {
$imagecache_path = imagecache_create_path($namespace, $path);
if ($image = image_get_info($imagecache_path)) {
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
}
else
// Try rebild or restore image, if it was deleted by any reasons
if ($preset = imagecache_preset_by_name($namespace)) {
if (imagecache_build_derivative($preset['actions'], $path, $imagecache_path)) {
if ($image = image_get_info($imagecache_path)) {
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
}
}
}
// check is_null so people can intentionally pass an empty array of attributes to override
// the defaults completely... if
if (is_null($attributes)) {
$attributes['class'] = 'imagecache imagecache-' . $namespace;
}
$attributes = drupal_attributes($attributes);
$imagecache_url = imagecache_create_url($namespace, $path);
return '<img src="' . $imagecache_url . '" alt="' . check_plain($alt) . '" title="' . check_plain($title) . '" ' . $attributes . ' />';
}
Comments
Comment #1
joostvdl commentedThis solutions works very nice. I have implemented it by placing the above function in the template.php file. Rename the function name to: phptemplate_imagecache.
I have in my theme image directory a picture if no picture is uploaded With the folowing code I replace the empty picture result in my view:
Can you make a patch file and submit it in dev?
Comment #2
fizk commented