The preset preview doesn't show the image. Apache2 logs indicate a 404 on ../files/imagecache/thumb/imagecache_sample.png and if you manually create that dir/image it gets automatically deleted when reloading the preview.

Note: The imagecache_sample.png is saved in files/ not files/imagecache/

Comments

nestor718’s picture

Look at this thread for ideas ..

http://drupal.org/node/410200#comment-1822478

rewted’s picture

Seems to be all IIS stuff. Besides, the developers need to fix the issue in their release. Clearly I am not the only one experiencing this.

nestor718’s picture

Na, it's not IIS stuff but the mod I put in works with IIS something that doesn't seem to get much support from the apache crowd. But the problem you're having is the same across all the platforms in that they rely on too many factors to be "just right" to work. I've searched for answers for days and some even try work arounds modifying their .htaccess files to some looney settings that will in no way work for anyone else.

But the developers have been aware of these issues since at least 2007 because that's the oldest post pointing out this bug. Basically, they're working on integrating with drupal 7 so I don't think there's going to be much work done on the existing module.

Anyway, try this modification in your imagecache.module file, it should work with apache:

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = NULL) {
  $path = _imagecache_strip_file_directory($filepath);
  if (module_exists('transliteration')) {
    $path = transliteration_get($path);
  }
  $query = $bypass_browser_cache ? time() : $bypass_browser_cache;
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
    if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . file_directory_path() .'/imagecache/'. $presetname .'/'. $path)) {
        return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
    } else {
        return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
    }

    case FILE_DOWNLOADS_PRIVATE:
     return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
  }
}
nestor718’s picture

Note: The imagecache_sample.png is saved in files/ not files/imagecache/

This is the nature of the bug. When your system is set to public downloads, imagecache thinks the file is there so it will never move it to the destination path. You have to 'trick' the imagecache fuction (when in public downloads) that the path is non-existent so it will then move the source file to the temp dir, modify it and then move to the final destination.

For all that to work in the module's default configuration an number of factors have to be true, some of which might not be possible on every system. The above hack restores intended functionallity via a boolean test that will conclusively determine what method to use to produce the desired results.

rewted’s picture

Not sure how to implement this into the module code. Do I just go to end of the file and add:

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = NULL) {
$path = _imagecache_strip_file_directory($filepath);
if (module_exists('transliteration')) {
$path = transliteration_get($path);
}
$query = $bypass_browser_cache ? time() : $bypass_browser_cache;
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
case FILE_DOWNLOADS_PUBLIC:
if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . file_directory_path() .'/imagecache/'. $presetname .'/'. $path)) {
return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
} else {
return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
}

case FILE_DOWNLOADS_PRIVATE:
return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
}
}

nestor718’s picture

It's in the file 'imagecache.module' around line 216

You'll see this:

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = FALSE) {
  $path = _imagecache_strip_file_directory($filepath);
  $args = array('absolute' => TRUE, 'query' => $bypass_browser_cache ? time() : $bypass_browser_cache);
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/imagecache/'. $presetname .'/'. $path, $args);
  }
}

Replace with this exactly:

function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = NULL) {
  $path = _imagecache_strip_file_directory($filepath);
  if (module_exists('transliteration')) {
    $path = transliteration_get($path);
  }
  $query = $bypass_browser_cache ? time() : $bypass_browser_cache;
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
    if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . file_directory_path() .'/imagecache/'. $presetname .'/'. $path)) {
        return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
    } else {
        return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
    }

    case FILE_DOWNLOADS_PRIVATE:
     return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
  }
}

Make a copy of the existing one for back up and roll back if need be. Also, you'll have to get the {} correct or you'll get a parse error.

rewted’s picture

It was on line 310. I've excluded the ?php part as they only appear at the top and bottom of the file. The following error is returned when adding a preset.

Fatal error: Unsupported operand types in /var/www/domain.com/includes/common.inc on line 1386

Going back, the preset is then listed there. But when trying to then edit the preset, same error.

Fatal error: Unsupported operand types in /var/www/domain.com/includes/common.inc on line 1386

Any idea?

 289 /**
 290  * Return a URL that points to the location of a derivative of the
 291  * original image transformed with the given preset.
 292  *
 293  * Special care is taken to make this work with the possible combinations of
 294  * Clean URLs and public/private downloads. For example, when Clean URLs are not
 295  * available an URL with query should be returned, like
 296  * http://example.com/?q=files/imagecache/foo.jpg, so that imagecache is able
 297  * intercept the request for this file.
 298  *
 299  * This code is very similar to the Drupal core function file_create_url(), but
 300  * handles the case of Clean URLs and public downloads differently however.
 301  *
 302  * @param $presetname
 303  * @param $filepath
 304  *   String specifying the path to the image file.
 305  * @param $bypass_browser_cache
 306  *   A Boolean indicating that the URL for the image should be distinct so that
 307  *   the visitors browser will not be able to use a previously cached version.
 308  *   This is
 309  */
 310 function imagecache_create_url($presetname, $filepath, $bypass_browser_cache = NULL) {
 311   $path = _imagecache_strip_file_directory($filepath);
 312   if (module_exists('transliteration')) {
 313     $path = transliteration_get($path);
 314   }
 315   $query = $bypass_browser_cache ? time() : $bypass_browser_cache;
 316   switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
 317     case FILE_DOWNLOADS_PUBLIC:
 318     if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . file_directory_path() .'/imagecache/'. $presetname .'/'. $path)) {
 319         return url($GLOBALS['base_url'] . '/' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
 320     } else {
 321         return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
 322     }
 323 
 324     case FILE_DOWNLOADS_PRIVATE:
 325      return url('system/files/imagecache/'. $presetname .'/'. $path, $query, NULL, TRUE);
 326   }
 327 }

troublescoot’s picture

Hey guys, I had the exact same problem and tried enabling the ImageAPI GD2 module. It worked perfectly after that, no modifications to the code. Hope this helps.

rewted’s picture

That has nothing to do with the issue, but thanks.

rewted’s picture

Bump, #7 requires an answer still.

rewted’s picture

After a week of fiddling around, I have a fix for this issue. Check out this thread: http://drupal.org/node/536596

FrankT’s picture

I have the same problem with the error message in #7, too. The fix mentioned (#536596: Imagecache FIX for images being created in wrong location) does not help. The files are created in the directory files directly instead of the appropriate subdirectory.

FrankT’s picture

Priority: Normal » Critical

...setting this issue on critical because this error causes the module not to do what it is meant for...

sholn’s picture

try to enable clean urls it worked for me

FrankT’s picture

... I already had clean URLs enabled ...

marcofabian’s picture

It works now, in my case, I enabled the Image API GD2

errorist’s picture

That solved my problem :)
Thanks

moxwai’s picture

Yeh enabling clean URL's fixed this for me. I'm using Bluehost and to get clean-urls going i had to make sure there was a .htaccess in the root of my drupal install that included the line:

RewriteBase /~bluehost_username/dressagetaranaki.co.nz

dressagetaranaki.co.nz being the name of the sub folder my site is in the root of bluehost.

Then i enable clean-urls, went back to my view and image cache images were all there! woo &#%(#@* hoo!

robbertnl’s picture

Same issue. Solutions not working here (like FrankT ) Tryed the latest release and the latest dev version. Clean urls are enabled, Image API GD2 also enabled

fizk’s picture

Priority: Critical » Normal
Status: Active » Closed (cannot reproduce)