Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/wp-admin/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ static function ( $classes ) {
'/?_fields=' . implode(
',',
array(
'animated_image_subsizes',
'description',
'gmt_offset',
'home',
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static function ( $classes ) {
'/?_fields=' . implode(
',',
array(
'animated_image_subsizes',
'description',
'gmt_offset',
'home',
Expand Down
21 changes: 21 additions & 0 deletions src/wp-includes/rest-api/class-wp-rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,27 @@ public function get_index( $request ) {
*/
/** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */
$available['image_max_bit_depth'] = (int) apply_filters( 'image_max_bit_depth', 16, 16 );

/**
* Filters whether sub-sizes of animated images should keep their animation.
*
* By default, sub-sizes of animated images (e.g. animated GIFs) are static,
* generated from the first frame only. Re-encoding every frame per sub-size
* is very resource intensive, so animated sub-sizes are opt-in.
*
* This currently only affects the client-side media processing path,
* where all frames can be decoded and re-encoded in the browser. Only
* uncropped sub-sizes keep their animation; cropped sizes (such as
* `thumbnail`) are always generated from the first frame. Uploads that
* take the server-side path also still produce static sub-sizes, as
* neither GD nor Imagick resizing preserves animation in core.
*
* @since 7.2.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @since 7.2.0
* @since 7.1.0

If this PR is to be committed during the 7.1 beta, let's update this.

*
* @param bool $animated_image_subsizes Whether to generate animated sub-sizes
* for animated images. Default false.
*/
$available['animated_image_subsizes'] = (bool) apply_filters( 'wp_generate_animated_image_subsizes', false );

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.

As I just commented at WordPress/gutenberg#80385 as well, animated_image_subsizes sounds more like an array than a boolean. Maybe we can prefix the field with generate_ as well or so.

}

$response = new WP_REST_Response( $available );
Expand Down
8 changes: 8 additions & 0 deletions tests/phpunit/tests/rest-api/rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ public function test_get_index() {

/**
* @ticket 64804
* @ticket 65656
*
* @covers WP_REST_Server::get_index
*/
Expand All @@ -1230,10 +1231,13 @@ public function test_get_index_should_include_media_processing_settings(): void
$this->assertTrue( $data['image_strip_meta'] );
$this->assertArrayHasKey( 'image_max_bit_depth', $data );
$this->assertSame( 16, $data['image_max_bit_depth'] );
$this->assertArrayHasKey( 'animated_image_subsizes', $data );
$this->assertFalse( $data['animated_image_subsizes'] );
}

/**
* @ticket 64804
* @ticket 65656
*
* @covers WP_REST_Server::get_index
*/
Expand All @@ -1250,10 +1254,12 @@ public function test_get_index_should_not_include_media_processing_settings_with
$this->assertArrayNotHasKey( 'image_size_threshold', $data );
$this->assertArrayNotHasKey( 'image_strip_meta', $data );
$this->assertArrayNotHasKey( 'image_max_bit_depth', $data );
$this->assertArrayNotHasKey( 'animated_image_subsizes', $data );
}

/**
* @ticket 64804
* @ticket 65656
*
* @covers WP_REST_Server::get_index
*/
Expand All @@ -1267,6 +1273,7 @@ public function test_get_index_should_honor_media_processing_filters(): void {
'image_max_bit_depth',
static fn ( int $max_depth ) => min( 8, $max_depth )
);
add_filter( 'wp_generate_animated_image_subsizes', '__return_true' );

$server = new WP_REST_Server();
$request = new WP_REST_Request( 'GET', '/' );
Expand All @@ -1275,6 +1282,7 @@ public function test_get_index_should_honor_media_processing_filters(): void {

$this->assertFalse( $data['image_strip_meta'] );
$this->assertSame( 8, $data['image_max_bit_depth'] );
$this->assertTrue( $data['animated_image_subsizes'] );
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -13063,6 +13063,7 @@ mockedApiResponse.Schema = {
"image_size_threshold": 2560,
"image_strip_meta": true,
"image_max_bit_depth": 16,
"animated_image_subsizes": false,
"site_logo": 0,
"site_icon": 0,
"site_icon_url": ""
Expand Down
Loading