#53667 closed defect (bug) (fixed)
Support `wp_editor_set_quality` for both loaded and saved `mime_type`s
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.8.1 | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Media | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
WordPress supports setting image quality via a filter, wp_editor_set_quality
.
This filter provides the mime_type
, which implies that the setting could conditionally apply to a certain MIME type only -- like in the example filter from this post:
// Use a quality setting of 75 for WebP images. function filter_webp_quality( $quality, $mime_type ) { if ( 'image/webp' === $mime_type ) { return 75; } return $quality; } add_filter( 'wp_editor_set_quality', 'filter_webp_quality', 10, 2 );
However, set_quality()
applies on load, but not on save. This means that if a different type is loaded than is saved (loading a JPEG, and saving WebP, for instance), that the filter would not apply to the latter mime_type
.
WordPress should apply the filter's details when saving as well.
Attachments (1)
Change History (24)
This ticket was mentioned in Slack in #core-media by desrosj. View the logs.
4 years ago
#3
@
4 years ago
We talked about this in a media meeting today.
There are more details there, but to leave what I've tried so far:
One possible solution for this would be to run set_quality()
during the save process if the output mime_type
is different, then again (to set it to the previous type's values) after the process is finished — a bit the way that Imagick currently does with image formats.
This should also be doable with GD.
I haven’t, as of yet, been able to get this exactly right / to an elegant solution, and I think it'd be a big change in set_quality()
behavior so close to release.
Ideally, this would have a good set of tests to make sure quality per mime type applies in both Imagick and GD properly during saving, and in the priority (#53669) expected.
#4
follow-up:
↓ 6
@
4 years ago
- Keywords has-patch added; needs-patch removed
In the media chat, these were the steps agreed upon for 5.8 to address this issue and #53668:
- Leave the filters in as is.
- Update the inline docs for the filter to explain that it is a bit experimental, and there are two known potential issues when using the filter to change image formats for sub sizes.
- Post a developer note detailing these two edge cases.
- Follow up in 5.8.x releases to fix these edge cases.
53667.diff is an adjustment to the filter's inline documentation to make developer's aware of these two edge cases, and that the filter should generally be considered experimental.
This ticket was mentioned in Slack in #core-media by desrosj. View the logs.
4 years ago
#6
in reply to:
↑ 4
@
4 years ago
Replying to desrosj:
53667.diff is an adjustment to the filter's inline documentation to make developer's aware of these two edge cases, and that the filter should generally be considered experimental.
Looks good to me.
#8
@
4 years ago
- Keywords dev-feedback fixed-major commit added
Marking [51442] for backport consideration.
#12
@
4 years ago
Should we keep this ticket open to track that the wp_editor_set_quality
filter doesn't apply properly, since it'll still need to be fixed, even though we've marked image_editor_output_format
as experimental?
#13
@
4 years ago
- Milestone changed from 5.8 to 5.8.1
- Resolution fixed deleted
- Status changed from closed to reopened
Yes we should. Sorry, I closed on accident when I meant to move to 5.8.1.
This ticket was mentioned in Slack in #core by azaozz. View the logs.
4 years ago
This ticket was mentioned in PR #1622 on WordPress/wordpress-develop by azaozz.
4 years ago
#16
- Keywords has-patch has-unit-tests added; needs-patch removed
Introduce $output_mime_type
in WP_Image_Editor
and set it on saving the image if different from the original image's mime-type. Add tests.
Trac ticket: https://core.trac.wordpress.org/ticket/53667
4 years ago
#17
Also introduces WP_Image_Editor::get_default_quality( $mime_type )
to be able to have different default quality for different image formats.
Currently the quality is (re)set and the wp_editor_set_quality
filter runs only once when the output image type is different from the input image type. Can be changed to run every time on saving an image, for example when creating image sub-sizes.
This ticket was mentioned in Slack in #core-media by azaozz. View the logs.
4 years ago
#19
@
4 years ago
- Owner set to azaozz
- Resolution set to fixed
- Status changed from reopened to closed
In 51704:
#20
@
4 years ago
- Keywords commit added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopen for 5.8.1.
#21
@
4 years ago
- Version set to 5.8
[51704] looks good in my review and testing. Let's get it into 5.8.1 RC.
draganescu commented on PR #1622:
4 years ago
#23
@azaozz is this done in https://core.trac.wordpress.org/changeset/51712 ?
Going to move this to the milestone to see if we can figure out a solution before RC4.
I don't think this issue would be a huge deal to ship with 5.8, but it's definitely not ideal.