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

WordPress Trac noreply at wordpress.org
Wed Jul 27 14:58:57 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 adamsilverstein):

 Once idea to consider here instead of or in addition to the filter
 improvements would be adding a quality setting directly to
 `add_image_size` (see #56288). This would enable setting a "default"
 quality for each size (which could then still be filtered at run time.

 > Yes I agree, the main reason for my comment was to point out a possible
 limitation on the current quality filter (because of the line that checks
 if the quality is unmodified) that might not be obvious from the docs when
 testing it out.

 @birgire you are right, the current filter is not sufficient because it
 isn't run for each size, but rather for the image as a whole, then the
 same quality is used for all sizes. To enable the feature requested in
 this ticket, I believe the filter would need to run _for each size_
 passing the size name as context.

 > Probably another filter would be needed here to avoid the current
 limitations and allow it to target different intermediate sizes and
 formats. Also to avoid changing current behavior of the existing filter.

 Possibly a new filter, or possibly we could use the same filter - running
 it once for each size with the size name passed as a new context variable.
 Existing code would continue to function, however the filter would run
 multiple times instead of once. I'm not sure which approach would be
 better, I would look to existing filter patterns in core for precedent.

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


More information about the wp-trac mailing list