Hi there,
Today I have been trying to implement pngquant myself using hook_file_insert()
and image effects, then using the Image Optimize Effect contrib (also based on image effects) and at last using ImageAPI Optimize.
hook_file_insert()
is not called when an image style styled image (ie. thumbnail, medium, etc.) is inserted.
Image effect callback functions are first all being called and then applied to the image, this makes it harder to run image optimizers that should be run after all regular image handlers have been called. The Image Optimize Effect contrib (v.7.1) solves this by temporarily creating an image using GD, this does not work with ImageMagick (which delivers higher quality).
So I like (amongst other things) the way ImageAPI Optimize acts like an image toolkit and allows site admins to select any other available image toolkit for image processing. This way ImageAPI Optimize can run optimization scripts after a styled image has been created, but now the optimization settings are done site wide and not per image style which would be great for lossy optimization.
This could be 'easily' implemented since ImageAPI Optimize image process callback functions receive the $dst
(destination?) variable which contains an absolute path to the image, ie. D:\drupal\sites\SITENAME\files\styles\IMAGESTYLE\public\modules\image\sample.png
, from which we can derive the image style's machine name with which we can load the image style settings using image_styles()
. Depending on the optimization settings for the current image style we can customly optimize all images for this style.
Now we need to add an optimization image effect with a settings page just like the default ImageAPI Optimize settings page.
Is there any interest for certain functionality or is an add-on module (ImageAPI Optimize Image Effect?) maybe preferred?
Comments
Comment #1
jcisio CreditAttribution: jcisio commentedI think it is desirable to enable (with just on/off options) the optimization per image style.
I don't think we want to customize the tool per style though. What we could do is enable a controlled image quality per style (a "reduce quality to xx%" option, which is independent the optimization process). I know that the Image Style Quality already does it, but it is sub optimal because it resets the variable cache each time an image is generated). This module would be the best place to implement that.
Comment #2
jcisio CreditAttribution: jcisio commentedI'm interested in this feature. I'm going to do it.
Comment #3
dillix CreditAttribution: dillix commentedHi! Is there any progress with this feature?
Comment #4
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedHad some thoughts about this, at the moment, we're an image toolkit, right? And we have to do the nasty
eval
to be able to copy all the procedural functions from the existing toolkit to a new one. Basically, we'd really like to just extend a class, and implement a single different method: save, and we're done.Well, actually I think we can.
image_save
which is called byimage_style_create_derivative
calls through toimage_toolkit_invoke
to do the saving.Now the code for
image_toolkit_invoke
is:note how the function name to call, is built up from a property on the $image object. This is the exact same image object that is passed into an image style effect callback as the first parameter...so if you were to have an image effect for imageapi_optimize it could actually change the
$image->toolkit
string so that a different function was called when the image was eventually saved.This would allow:
eval
Realise that that would be quite a large change for the module, but potentially quite a nice combination of new features and cleanup.
Comment #5
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedStarted work on what I've outlined in #4 over in a sandbox:
https://www.drupal.org/sandbox/darthsteven/2614582
Currently, you need to use the old admin UI to set up the imageapi optimize stuff, and then switch the toolkit back to your default, and then add the image effect to your styles, but so, it works!
Comment #7
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedThis is basically done in the 7.x-2.x branch now.