Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] phpThumbOf + getResources/MIGX #48

Open
wm-simon opened this issue Jan 23, 2013 · 2 comments
Open

[Bug] phpThumbOf + getResources/MIGX #48

wm-simon opened this issue Jan 23, 2013 · 2 comments

Comments

@wm-simon
Copy link

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.

@mburtscher
Copy link

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

@oo12
Copy link

oo12 commented Feb 26, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants