phpThumbOf icon indicating copy to clipboard operation
phpThumbOf copied to clipboard

[Bug] phpThumbOf + getResources/MIGX

Open wm-simon opened this issue 12 years ago • 2 comments

If you use the same filename in different paths phpThumbOf will output the same file.

Resource 1: Filepath original: img/resrouce-1/file.jpg Filepath phpThumbOf: /assets/components/phpthumbof/cache/file.hash.jpg

Resource 2: Filepath original: img/resrouce-2/file.jpg Filepath phpThumbOf: /assets/components/phpthumbof/cache/file.hash.jpg

phpThumbOf uses the same file for both resources, because the path is not considered.

wm-simon avatar Jan 23 '13 09:01 wm-simon

This seems to be a new bug! We hadn't had this issue before.

Using modx 2.2.6-pl and phpthumbof 1.4.0

mburtscher avatar Jan 28 '13 07:01 mburtscher

Quick fix: set phpthumbof.hash_thumbnail_names to Yes in System Settings.

If you have this turned off (the default) so your filenames are in this format file_name.options_hash.file_extension (for example: slide1.17257f7f69358c7cfb0c8d1dd1b859a014.jpg ) then the way phpthumbof generates filenames creates two potential problems.

  1. the one you mentioned: same base filename + same phpthumb options + same resource + different paths = same output filename.
  2. there's another problem too: same path + same base filename + same phpthumb options + different resource = different output filenames.

I have a site with a few hundred pages, and many of those pages use the same 4 images for one part (sized by phpthumbof). I happened to look in phpthumbof's cache and was surprised to find thousands of versions of the same 4 files!

I tracked it down to line 306 in core/components/phpthumbof/model/phpthumbof/phpthumbof.class.php:

$this->cacheFilename .= '.'.md5(serialize($this->options)).$this->modx->resource->get('id');

$this->cacheFilename is the base name of the file (so 'slide1' in the example above). You can see what's going wrong. Seems a better way to do it would be this:

 $this->cacheFilename .= '.' . md5( serialize($this->options) . pathinfo($inputSanitized, PATHINFO_DIRNAME) );

I think that will fix both your problem and mine. That changes the "equations" above to:

  1. same base filename + same phpthumb options + same resource + different paths = different output filenames
  2. same path + same base filename + same phpthumb options + different resource = same output filename

Or am I missing something? If hash collisions are a problem with the extra data in there, switching to sha1–only marginally slower than md5–would probably solve it.

oo12 avatar Feb 26 '13 19:02 oo12