I am using WP_Image_Editor through the Timber plugin and it's TimberImageHelper class. In my theme code I have:
TimberImageHelper::resize($path,$w,$h,$cropArea);, which eventually (after various manipulations of the filename and math to do with resizing and cropping) boils down to something like this :
$image = wp_get_image_editor( $load_filename ); $image->crop( $src_x, 0, $src_wt, $src_h, $w, $h ); $result = $image->save( $save_filename );
Google page insights is currently telling me I ought to be losslessly compressing my images, with most reporting optimizations of roughly 50%. This is a big difference and I want to pursue it, but I can't see a good way to use lossless compression with the TimberImageHelper OR with WP_Image_Editor directly so far.
I know I can filter the default quality to be used when resizing but I have the impression (correct me if it's wrong) that this is lossy compression and will bomb the image quality.
I've seen that there are the EWWW, TinyPNG/JPG and kraken.io plugins and have read a few articles about them. I guess they are an option, however currently the site is designed for late image manipulations (various pages use a wide array of sizes of images, which are created on demand rather than on upload), which have some logic in PHP to work on non-standard crop fits and such. Basically, if it were a plugin I would like it to be one that is totally unobtrusive in Wordpress other than offering me some calls (similar to TimberImageHelper::resize) that I can call. I guess I am more looking for a library than a WP Plugin.
Is there a way to achieve this with the default WP_Image_Editor that I have missed (or should I just be using the 1-100 quality filter)? Is there a good library/plugin etc that will give me the methods/functions to achieve lossless compression and resizing, without making other changes or introducing other filters/actions to the wordpress ecosystem to change image functions directly?