The Sheriff is an idiot. I've met smarter sandwiches

Drupal - imagecache problems with special characters

If you upload an image with an ampersand (&) in the filename, imagecache will refuse to display the image.
After a bit of investigation I found that imagecache has a problem with a number of special characters in the image filenames.

The solution is a little imagecache theme override in the template.php
Just copy & paste this code to the end of your template.php in the theme folder.

function phptemplate_imagecache($presetname, $path, $alt = '', 
$title = '', $attributes = NULL, $getsize = TRUE) {
  // 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);
  // here we add drupal_urlencode to make sure the path is encoded.
  $imagecache_url = imagecache_create_url($presetname, drupal_urlencode($path));
  return ''. check_plain($alt) .'';
}

Comments

Think you'll want to have a

Think you'll want to have a look at:
http://drupal.org/project/transliteration

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <code>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.