Hang on...

Drupal - imagecache problems with special characters

Share |

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 '<img class="mceItem" title="'. check_plain($title) .'" src="'.$imagecache_url.'" alt="'. 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> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <caption> <tbody> <tr> <td> <em> <b> <u> <i> <strong> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike>
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options