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

joostvdl’s picture

This 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:

global $theme_path;
 
 if(empty($view->field['field_mbprof_picture_fid']->original_value)) {
 	$namespace = 'avatar';
	$image_name = 'man_nophoto_icoon.png';
	$path = $theme_path . '/images/'.$namespace.'/' . $image_name;
	$output = theme('imagecache', $namespace, $path);
 }

Can you make a patch file and submit it in dev?

fizk’s picture

Status: Active » Closed (won't fix)