Media: Return the filtered wp_editor_set_quality value in the upload response#78420
Media: Return the filtered wp_editor_set_quality value in the upload response#78420adamsilverstein wants to merge 2 commits into
wp_editor_set_quality value in the upload response#78420Conversation
Client-side media processing encoded sub-sizes and threshold-scaled images at a hardcoded quality (DEFAULT_OUTPUT_QUALITY), bypassing the wp_editor_set_quality filter so server-side quality tuning had no effect. Add a size-aware image_quality field to the attachment REST response, mirroring the image_output_format / image_save_progressive pattern. The filter is resolved against the output MIME type for the full image and re-applied per registered sub-size, reporting only sizes whose quality diverges from the default. upload-media consumes this when resizing and transcoding sub-sizes, falling back to the previous default when the field is absent (older Core). Closes #78419
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +114 B (0%) Total Size: 7.97 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in c648922. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26066791882
|
|
Good idea! I was about to leave more feedback (I noticed that this isn't handling the I'll hold off reviewing properly until that's settled 😄 |
Summary
image_qualityfield to the attachment REST response so client-side media processing honors thewp_editor_set_qualityfilter@wordpress/upload-mediauses the filtered quality when resizing and transcoding sub-sizes (and the threshold-scaled copy), instead of the hardcodedDEFAULT_OUTPUT_QUALITYimage_output_format/image_save_progressive/exif_orientationpattern: per-file image-processing decisions live in the per-attachment upload response where the real filename, output MIME type, and dimensions are availableCloses #78419
Approach
Gutenberg_REST_Attachments_Controller::prepare_item_for_response()resolves the output MIME type the same way core'sWP_Image_Editor::set_quality()does (afterimage_editor_output_format), then applieswp_editor_set_qualitywith that MIME type and:defaultsizesonly when the filtered value diverges fromdefault(keeps the payload small)wp_editor_set_qualityhas been size-aware since WP 6.8 (( int $quality, string $mime_type, array $size )).The client converts the 1-100 WordPress scale to the 0-1 scale the vips worker expects, applies it per sub-size resize/transcode, and falls back to the previous default when the field is absent (older Core).
Test plan
image_quality.defaultis82(JPEG) with emptysizesand no behavior changewp_editor_set_qualityfilter (e.g. lower quality for thumbnails) and verify the per-size value appears in the REST response and is used when generating sub-sizesimage_editor_output_formatJPEG→WebP filter shiftsdefaultto the WebP default (86)npm run test:unit packages/upload-mediavendor/bin/phpunit phpunit/media/class-gutenberg-rest-attachments-controller-test.php