Skip to content

Media: Add an opt-in filter to generate animated image sub-sizes#12572

Open
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:add/animated-image-subsizes-filter
Open

Media: Add an opt-in filter to generate animated image sub-sizes#12572
adamsilverstein wants to merge 2 commits into
WordPress:trunkfrom
adamsilverstein:add/animated-image-subsizes-filter

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jul 16, 2026

Copy link
Copy Markdown
Member

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_subsizes filter (boolean, default false) and exposes its value on the REST API index as animated_image_subsizes, inside the existing client-side media processing block in WP_REST_Server::get_index() (alongside image_size_threshold, only for users who can upload_files). When a site opts in, the client pipeline keeps the animation in uncropped sub-sizes of animated GIFs; cropped sizes such as thumbnail always 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.php and wp-admin/site-editor.php - these must match packages/core-data/src/entities.js exactly for preloading to work, and the matching entities.js change is part of the Gutenberg PR. (Note: #12508 may want to do the same for image_strip_meta / image_max_bit_depth.)

The client-side consumption (editor settings plumbing, @wordpress/upload-media, and the @wordpress/vips worker 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


Proposed commit message

Media: Add an opt-in filter to generate animated image sub-sizes.

Sub-sizes of animated images have always been static first-frame images: GD and Imagick flatten animated images when resizing, and re-encoding every frame per sub-size is very resource intensive. The client-side media processing path can preserve animation in the uploading user's browser, independent of host Imagick availability.

Add a new wp_generate_animated_image_subsizes filter (boolean, default false) and expose it on the REST API index alongside the other client-side media processing settings, so the client pipeline can honor it for uncropped sub-sizes. The client-side consumption ships via the Gutenberg package updates in https://github.com/WordPress/gutenberg/pull/80385.

Fixes #65656. See #28474, #64804.

… 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.
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@adamsilverstein
adamsilverstein marked this pull request as ready for review July 16, 2026 23:58
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines +1254 to +1256
$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
$this->assertIsInt( $user_id );
wp_set_current_user( $user_id );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants