Disable “smart” compression mode in Imagify
Published: – Leave a comment
Starting with version 2.0, Imagify implemented a “smart” compression mode that replaced the previous modes “normal”, “aggressive” and “ultra”. Unfortunately, it doesn’t seem to be that smart at all.
This new compression mode uses AI to determine the best compression mode for the given image. There’s no more option for you to tell Imagify which compression mode to use. The only alternative is the also new compression mode “lossless”, which produces much larger files than any of the other compression modes and had to be selected for every media manually.
There are multiple users complaining about this “smart” compression mode (e.g. here or here), since it doesn’t work well for them. I had the same problem and this way the plugin was unusable for me, since the chosen compression mode by the AI was always – really always – way too aggressive.
Since there was no real help from the support of WP Media except from a message saying that they will re-introduce a lossless option, but couldn’t say anything about an ETA, I looked for a quick solution.
First I tried to override the setting for the compression mode. But the plugin won’t allow that, this setting will explicitly deleted. It’s never desired by the plugin to override that. So I dug deeper and finally found how to disable the smart compression mode for all images. It’s stored as metadata of the media file as compression level from 0 to 3 (where 0 is lossless and 1, 2 and 3 are all smart, since it originally were normal, aggressive and ultra). When you just override these values, you can decide at least between lossless and smart:
<?php
/**
* Reset the optimization level of Imagify since 'smart' isn't actually smart.
*
* @see https://wordpress.org/support/topic/smart-optimization/
* @see https://wordpress.org/support/topic/smart-compression-killed-the-plugin/
*
* @param mixed $value The current meta data value
* @param int $object_id The object ID
* @param string $meta_key The metadata key
* @return mixed The value or 0 for the optimization level
*/
function my_imagify_reset_optimization_level( $value, $object_id, $meta_key ) {
if ( $meta_key !== '_imagify_optimization_level' ) {
return $value;
}
return 0;
}
add_filter( 'get_post_metadata', 'my_imagify_reset_optimization_level', 10, 3 );
Code language: PHP (php)
Besides now having all media compressed in a lossless variant (which reduces the media sizes round about 20 %; by contrast: I had up to 80 % reduction before the “smart” compression mode with nearly no visible impact), a huge reason why we used Imagify is gone now. There are plenty of alternatives and I will definitely give them a try.