The way this module works is that when an image derivative needs to be created with a different JPEG quality than the site-wide default, the module calls variable_set() to change the JPEG quality for the page request that generates the image style, then variable_set() again to set it back on the next page request, during hook_init().
There are two problems with this:
- The frequent flip-flopping of variables is bad for performance; every single time variable_set() is called it writes to the database and clears the entire variables cache which then needs to be rebuilt on subsequent page requests. It's not something that should be frequently called.
- Under some circumstances, hook_init() is too late to reset the variable and therefore other images can (erroneously) have their image derivatives generated using the incorrect JPEG quality earlier in the page request, before the variable is reset. I saw this on a site that was using the Media module and the Image Resize Filter module such that images are embedded in the node body => roughly it goes something like menu_get_custom_theme() => _menu_load_objects() => node_load() => text_field_load => check_markup() => image_resize_filter_process_filter() => image_style_create_derivative(). There are probably other scenarios also.
The fix should be simple. Instead of using variable_set() to write the temporary variable values to the database, simply override them for the current page request only.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | image-style-quality-remove-frequent-variable-set-calls-2346525-1.patch | 2.09 KB | David_Rothstein |
Comments
Comment #1
David_Rothstein commentedHere's a patch that does that.
Comment #3
sam152 commentedComment #4
David_Rothstein commentedThanks for the quick commit, and the extra code changes! (I missed that the "image_style_quality_global_quality" variable is no longer needed after this patch, but indeed that's the case.)
Comment #5
sam152 commentedNot a problem. Thanks for bringing this to my attention and writing a patch, it has been a while since I have put any time into the module, so good to see it make a positive evolution.