summaryrefslogtreecommitdiffstatshomepage
path: root/tests/phpunit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit')
-rw-r--r--tests/phpunit/data/images/png-tests/grayscale-test-image.pngbin0 -> 8843 bytes
-rw-r--r--tests/phpunit/data/images/png-tests/vivid-green-bird.pngbin0 -> 2625142 bytes
-rw-r--r--tests/phpunit/tests/image/editorImagick.php61
3 files changed, 59 insertions, 2 deletions
diff --git a/tests/phpunit/data/images/png-tests/grayscale-test-image.png b/tests/phpunit/data/images/png-tests/grayscale-test-image.png
new file mode 100644
index 0000000000..10f537a71b
--- /dev/null
+++ b/tests/phpunit/data/images/png-tests/grayscale-test-image.png
Binary files differ
diff --git a/tests/phpunit/data/images/png-tests/vivid-green-bird.png b/tests/phpunit/data/images/png-tests/vivid-green-bird.png
new file mode 100644
index 0000000000..7b55b3d5e7
--- /dev/null
+++ b/tests/phpunit/data/images/png-tests/vivid-green-bird.png
Binary files differ
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.
+ ),
+ );
+ }
}