[wp-trac] [WordPress Trac] #54648: Improve filter to enable setting quality for each subsize image

WordPress Trac noreply at wordpress.org
Fri Jul 1 22:39:56 UTC 2022

#54648: Improve filter to enable setting quality for each subsize image
 Reporter:  Mte90                       |       Owner:  adamsilverstein
     Type:  enhancement                 |      Status:  accepted
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  Media                       |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:  performance

Comment (by birgire):

 I'm not up to date on this, but I just recalled playing with this many
 years ago (2014) here


 to modify the image quality before the image size is generated.

 Let me just quote my comment there in case it might still apply here:


 > I almost managed to solve this with only filters
 > image_resize_dimensions and jpeg_quality filter) within a custom class,
 but was stopped by single
 > line in the get_quality() method of the WP_Image_Editor class. It's the
 check: if ( ! $this->quality ),
 > that's made before the jpeg_quality filter is activated. That means you
 can only use that filter
 > once, for all intermediate jpeg image sizes. So if we want to modify the
 quality before the files are
 > saved, then I don't see another way then to extend the class as I did in
 my answer ;-)

 The {{{jpeg_quality}}} has since been deprecated for

 I might be refering there to this line here:


 in this method:

         public function get_quality() {
                 if ( ! $this->quality ) {

                 return $this->quality;

Ticket URL: <https://core.trac.wordpress.org/ticket/54648#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list