Repository navigation
Media: Add an opt-in filter to generate animated image sub-sizes - #12572
adamsilverstein wants to merge 6 commits into
Conversation
… index. Sub-sizes of animated images are static first-frame images by default because re-encoding every frame per sub-size is very resource intensive. The client-side media processing path can preserve animation in the browser, so expose an opt-in flag on the REST API index (alongside image_size_threshold) that the client pipeline honors for uncropped sub-sizes. See WordPress/gutenberg#80383 and WordPress/gutenberg#80385.
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. |
|
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. |
| $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); | ||
| $this->assertIsInt( $user_id ); | ||
| wp_set_current_user( $user_id ); |
There was a problem hiding this comment.
| $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); | |
| $this->assertIsInt( $user_id ); | |
| wp_set_current_user( $user_id ); | |
| wp_set_current_user( self::$admin_id ); |
Reuse admin that already created in wpSetUpBeforeClass
There was a problem hiding this comment.
I don't think this is a blocker, since this PR doesn't touch these lines.
|
Just noting we have decided to land this in 7.2. |
…ubsizes-filter # Conflicts: # src/wp-includes/rest-api/class-wp-rest-server.php # tests/phpunit/tests/rest-api/rest-server.php # tests/qunit/fixtures/wp-api-generated.js
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DxbbMKz3sa741SjHuE1ZLS
A bare `animated_image_subsizes` reads like an array of sizes rather than a boolean. Prefix it with `generate_` so the field name mirrors the filter it exposes, and keep the preload field lists alphabetical so they still match the editor's entities.js list exactly. Claude-Session: https://claude.ai/code/session_018uRsBsDb9t3piAjyWaycCo
t-hamano
left a comment
There was a problem hiding this comment.
Pre-approving this prior to WordPress/gutenberg#80385.
Just in case, it might be better to wait to commit this PR until WordPress/gutenberg#80385 is merged and confirmed to be shipped in 7.2. Otherwise, a mismatch may occur between the preload list and entities.js.
| $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); | ||
| $this->assertIsInt( $user_id ); | ||
| wp_set_current_user( $user_id ); |
There was a problem hiding this comment.
I don't think this is a blocker, since this PR doesn't touch these lines.
|
Looks good. Clean opt-in approach for preserving animated GIF sub-sizes via the client-side pipeline. Happy to test once both sides are ready. |
Core backport of the server-side changes in WordPress/gutenberg#80385 (design discussion in WordPress/gutenberg#80383).
Resized versions of animated GIFs have always lost their animation - the subject of the 12-year-old Trac #28474, which stalled server-side because GD cannot preserve frames and Imagick is only available on a subset of hosts. The client-side media processing path can decode and re-encode every frame in the uploading user's browser, independent of host configuration, making animation-preserving sub-sizes feasible as a developer opt-in (they remain too expensive to be the default).
This adds the new
wp_generate_animated_image_subsizesfilter (boolean, defaultfalse) and exposes its value on the REST API index asgenerate_animated_image_subsizes, inside the existing client-side media processing block inWP_REST_Server::get_index()(alongsideimage_size_threshold, only for users who canupload_files). When a site opts in, the client pipeline keeps the animation in uncropped sub-sizes of animated GIFs; cropped sizes such asthumbnailalways flatten to the first frame.The field is also added to the block editor root-index preload field lists in
wp-admin/edit-form-blocks.phpandwp-admin/site-editor.php- these must matchpackages/core-data/src/entities.jsexactly for preloading to work, and the matching entities.js change is part of the Gutenberg PR. (Note: #12508 may want to do the same forimage_strip_meta/image_max_bit_depth.)The client-side consumption (editor settings plumbing,
@wordpress/upload-media, and the@wordpress/vipsworker restoring the all-frames load path with tuned GIF encoder settings) ships via the Gutenberg package updates in WordPress/gutenberg#80385.Trac ticket: https://core.trac.wordpress.org/ticket/65656
Testing Instructions
Proposed commit message
AI Use
The code and this description came out of a session with 🤖 Claude Code. I will review and test.