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?


1 Answer 1


With @jgraup 's help in comments, I had a look at the responsive images plugin linked there. While that particular one has several other filters on things like post content which I would have preferred not to use, the RespImg class included is exactly what I was wanting. I was originally considering what would be required to remove all the filters added by the plugin... it's only 5 or 6, however I found a more barebones version of the same class here: https://github.com/nwtn/wp-respimg . It does not include any of the filters other than the one to add that editor class, and dropped into my project nicely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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