diff options
-rw-r--r-- | src/wp-admin/nav-menus.php | 2 | ||||
-rw-r--r-- | src/wp-content/themes/twentyeleven/inc/block-patterns.php | 4 | ||||
-rw-r--r-- | src/wp-includes/class-wp-image-editor-imagick.php | 51 | ||||
-rw-r--r-- | tests/phpunit/data/images/png-tests/grayscale-test-image.png | bin | 0 -> 8843 bytes | |||
-rw-r--r-- | tests/phpunit/data/images/png-tests/vivid-green-bird.png | bin | 0 -> 2625142 bytes | |||
-rw-r--r-- | tests/phpunit/tests/image/editorImagick.php | 61 |
6 files changed, 83 insertions, 35 deletions
diff --git a/src/wp-admin/nav-menus.php b/src/wp-admin/nav-menus.php index 36905bab63..82c8e264ad 100644 --- a/src/wp-admin/nav-menus.php +++ b/src/wp-admin/nav-menus.php @@ -1083,7 +1083,7 @@ require_once ABSPATH . 'wp-admin/admin-header.php'; $menu_name_aria_desc = $add_new_screen ? ' aria-describedby="menu-name-desc"' : ''; if ( $one_theme_location_no_menus ) { - $menu_name_val = 'value="' . esc_attr( 'Menu 1' ) . '"'; + $menu_name_val = 'value="' . esc_attr__( 'Menu 1' ) . '"'; ?> <input type="hidden" name="zero-menu-state" value="true" /> <?php diff --git a/src/wp-content/themes/twentyeleven/inc/block-patterns.php b/src/wp-content/themes/twentyeleven/inc/block-patterns.php index bdb2619422..27b37be500 100644 --- a/src/wp-content/themes/twentyeleven/inc/block-patterns.php +++ b/src/wp-content/themes/twentyeleven/inc/block-patterns.php @@ -39,7 +39,7 @@ if ( function_exists( 'register_block_pattern' ) ) { <!-- wp:columns --> <div class="wp-block-columns"><!-- wp:column --> <div class="wp-block-column"><!-- wp:image {"id":null,"sizeSlug":"large","linkDestination":"none"} --> - <figure class="wp-block-image size-large"><img src="' . esc_url( get_template_directory_uri() ) . '/images/patterns/pattern-flower.jpg" alt="' . esc_attr( 'A yellow flower against a dark background.', 'twentyeleven' ) . '" /></figure> + <figure class="wp-block-image size-large"><img src="' . esc_url( get_template_directory_uri() ) . '/images/patterns/pattern-flower.jpg" alt="' . esc_attr__( 'A yellow flower against a dark background.', 'twentyeleven' ) . '" /></figure> <!-- /wp:image --> <!-- wp:paragraph {"dropCap":true} --> <p class="has-drop-cap">' . esc_html__( 'This is just an example post to showcase the featured post section on the showcase page. Who doesn’t like flowers? I like flowers. Nullam hendrerit enim nunc. Vestibulum eget nulla magna! Fusce lobortis neque eu neque egestas tincidunt. Duis elementum consequat lorem, in eleifend justo mollis at. Nam quis adipiscing magna. Duis adipiscing est ac nibh feugiat rhoncus. Donec non lorem felis, eget commodo purus.', 'twentyeleven' ) . '</p> @@ -117,7 +117,7 @@ if ( function_exists( 'register_block_pattern' ) ) { <!-- /wp:heading --><!-- wp:columns --> <div class="wp-block-columns"><!-- wp:column --> <div class="wp-block-column"><!-- wp:image {"id":null,"sizeSlug":"large","linkDestination":"none"} --> - <figure class="wp-block-image size-large"><img src="' . esc_url( get_template_directory_uri() ) . '/images/patterns/pattern-woman.jpg" alt="' . esc_attr( 'Photo of a woman.', 'twentyeleven' ) . '" /></figure> + <figure class="wp-block-image size-large"><img src="' . esc_url( get_template_directory_uri() ) . '/images/patterns/pattern-woman.jpg" alt="' . esc_attr__( 'Photo of a woman.', 'twentyeleven' ) . '" /></figure> <!-- /wp:image --></div> <!-- /wp:column --> <!-- wp:column --> diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index 66085ac503..2e7c7039d5 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -484,37 +484,28 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $this->image->setOption( 'png:compression-filter', '5' ); $this->image->setOption( 'png:compression-level', '9' ); $this->image->setOption( 'png:compression-strategy', '1' ); - // Check to see if a PNG is indexed, and find the pixel depth. - if ( is_callable( array( $this->image, 'getImageDepth' ) ) ) { - $indexed_pixel_depth = $this->image->getImageDepth(); - - // Indexed PNG files get some additional handling. - if ( 0 < $indexed_pixel_depth && 8 >= $indexed_pixel_depth ) { - // Check for an alpha channel. - if ( - is_callable( array( $this->image, 'getImageAlphaChannel' ) ) - && $this->image->getImageAlphaChannel() - ) { - $this->image->setOption( 'png:include-chunk', 'tRNS' ); - } else { - $this->image->setOption( 'png:exclude-chunk', 'all' ); - } - - // Reduce colors in the images to maximum needed, using the global colorspace. - $max_colors = pow( 2, $indexed_pixel_depth ); - if ( is_callable( array( $this->image, 'getImageColors' ) ) ) { - $current_colors = $this->image->getImageColors(); - $max_colors = min( $max_colors, $current_colors ); - } - $this->image->quantizeImage( $max_colors, $this->image->getColorspace(), 0, false, false ); - - /** - * If the colorspace is 'gray', use the png8 format to ensure it stays indexed. - */ - if ( Imagick::COLORSPACE_GRAY === $this->image->getImageColorspace() ) { - $this->image->setOption( 'png:format', 'png8' ); - } + + // Indexed PNG files get some additional handling. + // See #63448 for details. + if ( + is_callable( array( $this->image, 'getImageProperty' ) ) + && '3' === $this->image->getImageProperty( 'png:IHDR.color-type-orig' ) + ) { + + // Check for an alpha channel. + if ( + is_callable( array( $this->image, 'getImageAlphaChannel' ) ) + && $this->image->getImageAlphaChannel() + ) { + $this->image->setOption( 'png:include-chunk', 'tRNS' ); + } else { + $this->image->setOption( 'png:exclude-chunk', 'all' ); } + // Set the image format to Indexed PNG. + $this->image->setOption( 'png:format', 'png8' ); + + } else { + $this->image->setOption( 'png:exclude-chunk', 'all' ); } } diff --git a/tests/phpunit/data/images/png-tests/grayscale-test-image.png b/tests/phpunit/data/images/png-tests/grayscale-test-image.png Binary files differnew file mode 100644 index 0000000000..10f537a71b --- /dev/null +++ b/tests/phpunit/data/images/png-tests/grayscale-test-image.png diff --git a/tests/phpunit/data/images/png-tests/vivid-green-bird.png b/tests/phpunit/data/images/png-tests/vivid-green-bird.png Binary files differnew file mode 100644 index 0000000000..7b55b3d5e7 --- /dev/null +++ b/tests/phpunit/data/images/png-tests/vivid-green-bird.png diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php index 8b00f3ac12..1edbf579c3 100644 --- a/tests/phpunit/tests/image/editorImagick.php +++ b/tests/phpunit/tests/image/editorImagick.php @@ -770,6 +770,8 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { * @ticket 36477 * * @dataProvider data_resizes_are_small_for_16bit_images + * + * @param string $file Path to the image file. */ public function test_resizes_are_small_for_16bit_images( $file ) { @@ -783,7 +785,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { $imagick_image_editor->resize( $size['width'] * .5, $size['height'] * .5 ); - $saved = $imagick_image_editor->save( $temp_file ); + $imagick_image_editor->save( $temp_file ); $new_filesize = filesize( $temp_file ); @@ -793,7 +795,7 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { } /** - * data_test_resizes_are_small_for_16bit + * Data provider for test_resizes_are_small_for_16bit_images. * * @return array[] */ @@ -816,4 +818,59 @@ class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { ), ); } + + /** + * Tests that the 'png:IHDR.color-type-orig' property is preserved after resizing + * Used to identify indexed PNG images, see https://www.w3.org/TR/PNG-Chunks.html#C.IHDR. + * + * @ticket 63448 + * @dataProvider data_png_color_type_after_resize + * + * @param string $file_path Path to the image file. + * @param int $expected_color_type The expected original color type. + */ + public function test_png_color_type_is_preserved_after_resize( $file_path, $expected_color_type ) { + + $temp_file = DIR_TESTDATA . '/images/test-temp.png'; + + $imagick_image_editor = new WP_Image_Editor_Imagick( $file_path ); + $imagick_image_editor->load(); + + $size = $imagick_image_editor->get_size(); + $imagick_image_editor->resize( $size['width'] * 0.5, $size['height'] * 0.5 ); + $imagick_image_editor->save( $temp_file ); + + $imagick = new Imagick( $temp_file ); + $actual_color_type = $imagick->getImageProperty( 'png:IHDR.color-type-orig' ); + + unlink( $temp_file ); + + $this->assertSame( (string) $expected_color_type, $actual_color_type, "The PNG original color type should be preserved after resize for {$file_path}." ); + } + + /** + * Data provider for test_png_color_type_is_preserved_after_resize. + * + * @return array[] + */ + public static function data_png_color_type_after_resize() { + return array( + 'vivid-green-bird_color_type_6' => array( + DIR_TESTDATA . '/images/png-tests/vivid-green-bird.png', + 6, // RGBA. + ), + 'grayscale-test-image_color_type_4' => array( + DIR_TESTDATA . '/images/png-tests/grayscale-test-image.png', + 4, // Grayscale with Alpha. + ), + 'rabbit-time-paletted-or8_color_type_3' => array( + DIR_TESTDATA . '/images/png-tests/rabbit-time-paletted-or8.png', + 3, // Paletted. + ), + 'test8_color_type_3' => array( + DIR_TESTDATA . '/images/png-tests/test8.png', + 3, // Paletted. + ), + ); + } } |