Opened 4 weeks ago
Closed 3 weeks ago
#65623 closed defect (bug) (fixed)
Media: expose image_strip_meta and image_max_bit_depth in the REST API index for client-side media processing
| Reported by: | adamsilverstein | Owned by: | adamsilverstein |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1 |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | has-patch needs-testing has-unit-tests commit |
| Cc: | Focuses: |
Description
When client-side media processing is active, image decoding, scaling, and encoding happen in the browser, so no server-side WP_Image_Editor is ever instantiated. A hooks audit (Gutenberg #80210) found that several server-side image-processing filters therefore never influence generated images. Two of them can be reconciled by exporting their filtered values to the client:
image_strip_meta— plugins use this to keep metadata on resized images. On the client path, generated sub-sizes currently always strip everything except color profiles, ignoring the filter.image_max_bit_depth— plugins use this to cap the bit depth of generated images, relevant for 10/12-bit HDR AVIF sub-sizes. On the client path the source bit depth is always preserved, ignoring the filter.
The proposed change exposes the filtered values of both hooks on the REST API index inside the existing client-side media processing block in WP_REST_Server::get_index(), alongside the already-exported image_size_threshold:
image_strip_meta(boolean, defaulttrue)image_max_bit_depth(integer, default16)
Because the server never decodes the image on this path, image_max_bit_depth is applied with 16 (the maximum depth the client encoder can produce) as both the value and the current depth; plugins lowering the cap (e.g. to 8) still take effect on client-generated images.
The client-side consumption of these values (settings plumbing and the wasm-vips encoder honoring them) ships via the Gutenberg package updates in Gutenberg PR #80218.
Related hooks that cannot be reconciled (wp_image_editors, image_memory_limit, image_make_intermediate_size) are being handled as documentation in the client-side media docs (Gutenberg #80216).
Change History (9)
This ticket was mentioned in PR #12508 on WordPress/wordpress-develop by @adamsilverstein.
4 weeks ago
#1
#2
@
4 weeks ago
I reviewed and tested the patch. The changes worked as expected, and the REST API now exposes the required values correctly for client-side media processing. I also didn't encounter any issues while testing, and everything appears to be functioning as intended. This looks like a good improvement. Thanks for the patch!
@adamsilverstein commented on PR #12508:
4 weeks ago
#3
Upstream PR has merged, this should be ready.
#7
@
4 weeks ago
Manual Test Report
I tested PR #12508 using WordPress Playground.
Test Environment
- WordPress: trunk with PR #12508
- Environment: WordPress Playground
- Browser: Google Chrome
- Operating system: Windows
Test Method
I checked the REST API index using wp.apiFetch().
I also used a temporary test plugin to modify the following filters:
image_strip_metaimage_max_bit_depth
Before the Patch
On an unpatched WordPress trunk Playground, the REST API index returned:
image_strip_meta: undefined image_max_bit_depth: undefined
This confirmed that the two properties were not exposed before the proposed change.
After the Patch
On the Playground generated from PR #12508, the default REST API index values were:
image_strip_meta: true image_max_bit_depth: 16
After applying custom filter values, the REST API index returned:
image_strip_meta: false image_max_bit_depth: 8
Result
The PR works as expected in my manual testing.
The new REST API index properties are present with their expected default values, and both properties correctly respect values supplied through their corresponding filters.
#8
@
4 weeks ago
Manual Test Report
I tested PR #12508 using WordPress Playground.
Test Environment
- WordPress: trunk with PR #12508
- Environment: WordPress Playground
- Browser: Google Chrome
- Operating system: Windows
Test Method
I checked the REST API index using wp.apiFetch().
I also used a temporary test plugin to modify the following filters:
image_strip_metaimage_max_bit_depth
Before the Patch
On an unpatched WordPress trunk Playground, the REST API index returned:
image_strip_meta: undefined image_max_bit_depth: undefined
This confirmed that the two properties were not exposed before the proposed change.
After the Patch
On the Playground generated from PR #12508, the default REST API index values were:
image_strip_meta: true image_max_bit_depth: 16
After applying custom filter values, the REST API index returned:
image_strip_meta: false image_max_bit_depth: 8
Result
The PR works as expected in my manual testing.
The new REST API index properties are present with their expected default values, and both properties correctly respect values supplied through their corresponding filters.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Core backport of the server-side changes in https://github.com/WordPress/gutenberg/pull/80218.
On the client-side media processing path no server-side
WP_Image_Editoris instantiated, so theimage_strip_metaandimage_max_bit_depthfilters never influence generated images (see the hooks audit in https://github.com/WordPress/gutenberg/issues/80210 and follow-up https://github.com/WordPress/gutenberg/issues/80216).This exposes the filtered values of both hooks on the REST API index inside the existing client-side media processing block in
WP_REST_Server::get_index()(alongsideimage_size_threshold), so the client encoder can honor them:image_strip_meta(bool): when a plugin disables stripping, the client keeps all metadata on generated sub-sizes instead of stripping everything except color profiles.image_max_bit_depth(int): caps the bit depth of client-generated images (relevant for 10/12-bit HDR AVIF sub-sizes). Since the server never decodes the image on this path, the filter is applied with 16 as both the value and the current depth; plugins lowering the cap still take effect.The client-side consumption of these values ships via the Gutenberg package updates (
@wordpress/vips,@wordpress/upload-media, editor settings plumbing) in https://github.com/WordPress/gutenberg/pull/80218.