When images are uploaded in the same size as set in 'preview' it can be that image_display calls _image_build_derivatives while this is not needed.

I have a situation here $node->images['_original'] contains the same path as $node->images['preview']

now image_display checks the path, that's OK

next it checks filemtime(file_create_path($node->images[$label])) < variable_get('image_updated', 0))

and this always returns true and it tries to recreate the images, but it won't recreate the preview as it's the same sie as _original.....

my files table does not contain an entry for 'preview'....

Comments

bwynants’s picture

actualy this is because preview was set at 550,550 and image was 550,433

_image_build_derivatives inserts the '_original' for these images

jsloan’s picture

I posted this issue here // regenerate images?

bwynants’s picture

jeah, same issue.

here's how I fix this until there is an 'official' patch is available...

function image_display(&$node, $label = 'preview', $attributes = array()) {
  // regenerate images?
  if (($label != '_original') && ($node->images[$label] != $node->images['_original'])) {
      if (!file_exists(file_create_path($node->images[$label])) ||
        filemtime(file_create_path($node->images[$label])) < variable_get('image_updated', 0)) {
      _image_build_derivatives($node, false);// never temp images
    }
  }
bwynants’s picture

bad fix, don't do it like that. Loading a node can put '_original' path in as well, causing it to never recreate the needed images...

bwynants’s picture

jsloan: I understand your problem and you are also right but it's definitely another issue...

What is my problem? It's even worse as yours :-).

eg. you put preview size at 640x480 in image settings

you upload an image of 550x400

now EVERY time someone watches the image the thumbnail is regenerated (as are other defined formats)!

Why?

At the moment the image is viewed you always view the original, there is no preview image created by _image_build_derivatives since the 'original' image is already smaller as the needed 'preview' image size. Image_display does a chack and always compares the date of the original image with the last time the image settings where changed.... it triggers _image_build_derivatives but _image_build_derivatives does not recreate the 'preview' image meaning the 'original' date is never changed and the preview image date is also not changed. However the thumbnail is recreated! Next time someone watches the image, same thing happens.....

I see 2 solutions

1) when _image_build_derivatives also 'touch' the original file...

2) remember or an image when the last call to _image_build_derivatives was made via an extra property ($node->image_derivatives_created ) when comparing if the settings changed date is newer do not compare it with the 'file creation date' but with the $node->image_derivatives_created property...

any other ideas?

walkah’s picture

Status: Active » Fixed

the big issue here is when the image file is the same as the _original (i.e. it doesn't get updated on build_derivatives)... I've added a check to avoid this.

please update to the latest version. thanks :)

bwynants’s picture

Status: Fixed » Needs review

did that, thanks, but what about my comment 4? if I change the settings and lower a size in the table that whas previous above or equal to original size that image is not recreated because it initially points to 'original' when loading the node...

drewish’s picture

Status: Needs review » Closed (fixed)

This version is no longer supported. If this issue is occurring with a more recent version please open a new issue.