filters – Where to hook to force WP to create compressed copy of uploaded image even if its small


I want to write a filter function and need help figuring out where it would be best to hook in or if there is any possibility at all.

My problem:

I am utilizing the jpeg_quality hook along with max_srcset_image_width hook and some custom intermediate sizes for optimization purposes.

The problem is that WP only makes a copy for an image only if a registered image size is lower then the original.

Say that my site has registered image sizes: 600×600, 1200×1200 and I set max_srcset_image_width to 1200 and jpeg_quality to 60. It works great unless the user uploads an image with resolution between 600×600 and 1200×1200. Then WP will only make the 600×600 copy, and use the original image for any situation that needs larger image. Often these original images have very low compression ratios which results in double or even triple size of what they would have been if the image was processed by WP.

What I plan to do is make it so that when WP finds that a registered image size is larger then the original, then it will proceed by making a copy with the same size as the original. That way it will utilize the compression ratio that is set in jpeg_quality.

Any help appreciated.

wwdes 2 years 2021-04-07T17:05:43-05:00 0 Answers 0 views 0

Leave an answer