0

I wish to run the following ImageMagick command before each image is saved to the server, how can I do so:

convert image_name.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB image_name.jpg

  • I would note that WordPress already has a compression filter, and recompresses for each resizing to 90%. By downgrading the quality to 85%, WordPress will then downgrade again resulting in double recompression, your medium/large/thumbnail images may look a lot worse. Also keep in mind not all images uploaded are jpeg's, and image operations can be expensive/slow – Tom J Nowell Aug 3 '17 at 11:53
  • But if I am intercepting the save function then I can write around the compression in order for it to only be compressed once – Mitchell Aug 3 '17 at 11:55
  • Would it not make more sense to tell WordPress to use 85% instead of 90% compression? If WP is already recompressing, you should try to hook into that and modify it, rather than replacing. Is this for image optimisation purposes or are you doing it for other reasons, such as reducing disk space usage – Tom J Nowell Aug 3 '17 at 14:29
0

WordPress already compresses jpeg files, doing it a second time will just degrade the quality with recompression artefacts

Instead, adjust the compression percentage via the jpeg_quality filter:

add_filter( 'jpeg_quality', function() {
    return 80; // 80%
});

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.