Jump to content

Hooks for manipulating images and its variations


AndZyk
 Share

Recommended Posts

Hello,

I am currently playing around to build my first module. It will be a simple module for the ImageOptim web service, but I am a little bit stuck on which right hook to use.

Currently I use following hook:

$this->pages->addHookAfter('saveFieldReady', $this, 'imageOptimSave');

I would like to pass images and its variations to the web service after adding them to the image field. But if I use the saveFieldReady hook only the original image will be optimized, not the API generated image variations, because they will be generated after viewing the page for the first time.

Can anybody please help me how to hook into the image variations? I already tried to use my own method, but this one used in the template would be called on every page render.

Regards, Andreas

  • Like 1
Link to comment
Share on other sites

Please do you a favour, (and all potentially additonal users of that said module): don't "optimize" the original image!

Those image optimization tools are useful to optimize all final variations, what means: optimize images that are only used to be displayed on the web.

Don't "optimize" images that you will need as source for variation creation.

  • Like 5
Link to comment
Share on other sites

After having a closer look to the AutoSmush module, I don't think there is not much need for the module I had in mind:

  • The ImageOptim web service requires an API key generated by your mail address
  • It is similar like reSmush.it currently free, but only in beta and it is not clear how long the beta will last

Also I should maybe develop a smaller module first. :lol:

If anyone wants to give this idea a shot, feel free to do so. If reSmush.it gets shut down for whatever reason, this could be an alternative.

@horst:

Forgive me this silly question: But does optimizing the source image really make an noticeable difference for creating the variations? Of course it makes sense, but so far I never noticed any downside. But I am not an image expert like you are. ;)

  • Like 2
Link to comment
Share on other sites

2 hours ago, AndZyk said:

If anyone wants to give this idea a shot, feel free to do so.

Hi @AndZyk Here is one: GlobalEmailSettings, such as: sender and reply to. See this recent discussion:

I'm not aware of any already published solutions to this and although it seems to be easy to implement and may not necessarily needs to be turned into a module, even a very simple module has the advantage of being ready made, easy to add and update (provided it is the the Module Directory...).

  • Like 2
Link to comment
Share on other sites

On 19.12.2016 at 8:40 PM, AndZyk said:

After having a closer look to the AutoSmush module, I don't think there is not much need for the module I had in mind:

  • The ImageOptim web service requires an API key generated by your mail address
  • It is similar like reSmush.it currently free, but only in beta and it is not clear how long the beta will last

Also I should maybe develop a smaller module first. :lol:

If anyone wants to give this idea a shot, feel free to do so. If reSmush.it gets shut down for whatever reason, this could be an alternative.

@horst:

Forgive me this silly question: But does optimizing the source image really make an noticeable difference for creating the variations? Of course it makes sense, but so far I never noticed any downside. But I am not an image expert like you are. ;)

Hi @AndZyk

it is not only that the Quality is affected, it results in higher filesizes too, sometimes. 

Im on mobile now. I May post a link later on, where you can see a comparison. 

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

In case somebody stumbles upon this thread looking for an ImageOptim plugin, I ended up creating one. It's very much inspired by the TinyPNG module.

ProcessWire ImageOptim module

To get a sense of where and when to create hooks for optimizing images on upload / resize, these two along with Autosmush could prove helpful.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...