Media: Fix GD editor leaking WebP-lossless quality into other output formats - #13300
Media: Fix GD editor leaking WebP-lossless quality into other output formats#13300irozum wants to merge 2 commits into
Conversation
…ts in the GD editor
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
WP_Image_Editor_GD::set_quality()checks$this->mime_type(the source image's mime type) instead of the output mime type when deciding whether to apply the WebP-lossless quality sentinel (IMG_WEBP_LOSSLESS, 101). Because of that, converting a lossless WebP source to any other format (AVIF, JPEG, etc.) still gets the quality forced to 101 — a value that is intentionally outside the normal[1,100]range and only valid for GD's WebP lossless encoder. On PHP 8.4+, passing 101 toimageavif()/imagejpeg()throws aValueError, producing a fatal error, 0-byte sub-sizes, and brokenwp media regenerateruns; on older PHP it silently applies the wrong quality to the non-WebP output.This fixes the mime check to use
$this->output_mime_typewhen it's set (falling back to$this->mime_type, matching the same fallback the parent class already uses inWP_Image_Editor::set_quality()), so the lossless override is only applied when the image is actually being encoded as WebP. It also removes the redundantparent::set_quality( $quality, $dims )call for the 101 sentinel, since that value is always rejected by the parent's[1,100]validation and itsWP_Errorreturn was being silently discarded — the direct$this->qualityassignment right below it was already the only thing doing anything.Added a PHPUnit test (
Tests_Image_Editor_GD::test_set_quality_does_not_leak_webp_lossless_quality_into_other_formats) that loads a lossless WebP fixture, saves it as JPEG, and asserts the quality used is the normal JPEG default (82) rather than the leaked WebP-lossless sentinel (101).Trac ticket: https://core.trac.wordpress.org/ticket/65977
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Root-cause analysis, implementation, tests, and PR description. Reviewed by Igor Rozum.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.