There are instances in which theme_imagecache will be called but nothing will be passed as a path. In my case, it was when I created a view of nodes with emfield videos, which use the emthumb feature that sends video thumbnails to imagecache. In the rows in which nodes had no video loaded in the emfield video field, imagecache still tries to process the thumbnail and produces a broken img tag.

I overrode theme_imagecache in my theme, adding the lines

   if (is_null($path)) {
    return '';

to the top of the function. I wonder if something like this should be in the module itself to make sure no broken images are produced i these cases.

Comments

goto10’s picture

I'm having the same problem!

If this is a fix that works, I'd love to implement it. However, the images in question are being displayed by a view and not by a theme function. Where would I drop this statement?

Also of note is a solution in the emfield issues: http://drupal.org/node/692956#new692956

Thanks!

-Jesse

dafeder’s picture

Here is the full theme function in my template.php.

function THEMENAME_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
   if (is_null($path)) {
    return '';
  }
  // 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);
  }
  if ($getsize && ($image = image_get_info(imagecache_create_path($presetname, $path)))) {
    $attributes['width'] = $image['width'];
    $attributes['height'] = $image['height'];
  }

  $attributes = drupal_attributes($attributes);
  $imagecache_url = imagecache_create_url($presetname, $path);
  return '<img src="'. $imagecache_url .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
}
danny englander’s picture

#2 worked for me, thanks, I thought this was going to be another needle in a haystack until I came across this page -- it that works great!

PMorris’s picture

You rock for posting this. Works perfect. I had some styles on my tags that I really wanted to keep, but having those empty divs and broken link everywhere in the html was driving me nuts

thrash632’s picture

I tried copying and pasting the code in #2 at the top of my template.php file, but it didn't do anything :(

Do I have to modify it in anyway first?

Here is an example:

http://www.adambadlotto.com/work/branding/dj-rob-riggs-identity

danny englander’s picture

@thrash632, did you change "THEMENAME" to the name of your theme and then clear the cache?

thrash632’s picture

I missed the part about the theme name. It's working now. My bad!

While this does remove the thumbnail, the label for the field is still being generated.

Here is an example:

http://www.adambadlotto.com/work/branding/peace-studies-identity

Is there a way to tell it to hide the field label as well?

Thanks.

thrash632’s picture

Also, the overlayed play button still displays too. You won't see it in the example I provided because I turned off the overlay button for the time being. I'm referring to the overlay image that emfield generates.

I can't figure out if this is an emfield issue or an imagecache issue. I wish a fix would come out though.

danny englander’s picture

You may need to make a custom-node.tpl.php with custom fields theming and a php if statement to hide if the field is empty.

thrash632’s picture

I wish I could, I'm not all too familiar with PHP at all :-/

Maybe someone could throw together some php for me ;-) I'm sure others would find it useful as well.

fizk’s picture

Status: Active » Closed (fixed)