If I upload a new version of an image that has the same filename (and dimensions and file size don't seem to matter) via an imagefield in a cck node, imagecache does not display the new version of the image, but keeps the old.
Only if I rename the image before uploading, the new image is displayed.

Comments

eigentor’s picture

Title: With new version of image (same filename) display is not updated » No Display of new version of image (same filename)

Browser refresh does not help in neither browser.

dopry’s picture

Version: 5.x-1.3 » 6.x-2.x-dev

does the filename not change when it's saved? I'm pretty sure drupal tried to create a new filename if an file by the same name already exists... There may be some need to watch via nodeapi to clear out cached images here....

eigentor’s picture

Indeed, Drupal creates a new filename, if the same image is saved again. If I do it several times, a filename_0.jpg
and a filename_1.jpg is created. If I continue uploading the same image, the filename_1.jgp is replaced by the new image, it does not count up further.

What do you mean by watch via nodeapi? I'm not a developer...

dopry’s picture

hmm... this sounds like a bug in core file handling.. I'll see If I can reproduce later today...

eigentor’s picture

I tracked the problem a little further. Imagecache got it's own folder in the files directory. As I see, the derivates are created the first time a page is called the derivate is displayed on.
When I upload a new Image, Imagecache should notice and replace this image I call the page the next time. But instead, it seems to take the image already stored.

If I delete this file and call the page once more, Imagecache creates a new file, now from the newly uploaded Image and thus correctly.

Appears to have something to do with this: as long as it finds the derivate in its folder it does not seem to check for a new original.

Or better: it does check for a new original, but does not seem to check the upload time stamp (hopefully there is one) or any time stamp or file size, but just the file name.

eigentor’s picture

edit - double post

eigentor’s picture

As I learn from this article: http://www.lullabot.com/articles/imagecache_example_user_profile_pictures
The behaviour is not a bug, but normal. Still, it needs fixing. Graciously Nate already provides a solution in the end:

/**
* Check for new or deleted uploads and clear the imagecache if necessary
*/
function imagecache_profiles_user_edit_submit($form_id, $form_values) {
  if (file_check_upload('picture_upload') || $form_values['picture_delete']) {
    imagecache_image_flush($form_values['picture']);
  }
}

Could this do the trick? Well, surely at least some of the code he used before this is needed to make it work.

dopry’s picture

Status: Active » Closed (fixed)

hmm.. yeah where ever you're implementing imagecache you have to deal with the flushing. It's a pain in the but I know, but if I spend all my time trying to integrate and support imagecache with everything I'll go insane ;)... I would suggest using a glue module for these types of situations....

eigentor’s picture

Well, hopefully it will be incorporated into the next version ;) When you hand a site off to a customer, you have to tell them to name the image differently, if they upload a new version. This is a - humm - acceptable workaround, but not on a longer term. Maybe most people just upload the image once and are done, so the behaviour does not get in their way too much. But doing galleries like this: http://portrait-hannover.de/stift/opa-mit-enkelbaby it is quite a pain.

For the moment I managed to instruct her to rename the file every time. But I'll get back to you the next time...

baja_tz’s picture

subscribe

vitvas’s picture

http://drupal.org/project/moduleweight (for Drupal 5)
(For example: imagefield weight: 1, imagecache weight: 0)

http://drupal.org/project/util (for Drupal 6)