[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
https://wordpress.stackexchange.com/questions/163844/create-image-formats-
with-different-qualities-when-uploading/165241#165241
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:
https://wordpress.stackexchange.com/questions/163844/create-image-formats-
with-different-qualities-when-uploading/165241#comment240183_165241
> I almost managed to solve this with only filters
(intermediate_image_sizes_advanced,
> 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
{{{wp_editor_set_quality}}}.
I might be refering there to this line here:
https://github.com/WordPress/wordpress-
develop/blob/a14324ca3af4eeff69406d3e59719a33f055f07e/src/wp-includes
/class-wp-image-editor.php#L224
in this method:
{{{
public function get_quality() {
if ( ! $this->quality ) {
$this->set_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