0

I am using this plugin here to compress images throughout my site: https://bitbucket.org/bulldogcreative/tinypng/src

Ideally I would like to synchronise a directory of existing images through that plugin. The plugin hooks on to file_after_save. So it compresses the images when a new image is uploaded, but it doesn't seem to run when EE synchronises and re-saves the file.

Any ideas if I am doing something wrong or if EE just doesn't trigger on that condition?

0

That event won't fire on a syncronisation, think about the flow...

Syncronisation happens after files are saved on the file system, it's designed to check the physical files and add any that are new to the database, it does not create files on upload and save them to the disk (which is where the file_save_after event occurs.

If you're interested, the sync code is on lines 1053 to 1178 of file /system/expressionengine/controllers/cp/content_files.php. I've scanned this code and don't see an obvious hook to get on board with I'm afraid :(

you could generate a script to do this job for you though, you can borrow some code from the content_files.php file that will help you understand how it iterates. As you iterate you can check if tinypng has generated a file yet, if not you could copy the file somewhere, delete it via the filemanager then re-add it. Re-adding the file from the temp locatio back into filemanager should cause the file_save_after event to fire!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.