diff --git a/src/Drivers/Gd/GdDriver.php b/src/Drivers/Gd/GdDriver.php index 47d5b35..f728a24 100644 --- a/src/Drivers/Gd/GdDriver.php +++ b/src/Drivers/Gd/GdDriver.php @@ -290,7 +290,7 @@ protected function modify( $transparentColorValue = imagecolortransparent($this->image); if ($transparentColorValue !== -1) { - $rgba = imagecolorsforindex($newImage, $transparentColorValue); + $rgba = imagecolorsforindex($this->image, $transparentColorValue); $transparentColor = imagecolorallocatealpha( $newImage, diff --git a/tests/Manipulations/FitTest.php b/tests/Manipulations/FitTest.php index 3672f8e..3feede1 100644 --- a/tests/Manipulations/FitTest.php +++ b/tests/Manipulations/FitTest.php @@ -119,3 +119,21 @@ [[250, 300], 250, 300], [[100, 100], 100, 100], ]); + +it('can fit a PNG palette image with transparency and preserve the signature', function ( + ImageDriver $driver, +) { + $fitDimensions = [438, 170]; + $expectedWidth = 438; + $expectedHeight = 170; + + $targetFile = $this->tempDir->path("{$driver->driverName()}/fit-palette-signature.png"); + + $driver->loadFile(getTestFile('palette-signature.png'))->fit(Fit::Max, ...$fitDimensions)->save($targetFile); + + $savedImage = $driver->loadFile($targetFile); + + expect($savedImage->getWidth())->toBe($expectedWidth); + expect($savedImage->getHeight())->toBe($expectedHeight); + assertMatchesImageSnapshot($targetFile); +})->with('drivers'); diff --git a/tests/TestSupport/testFiles/palette-signature.png b/tests/TestSupport/testFiles/palette-signature.png new file mode 100644 index 0000000..cc1dea2 Binary files /dev/null and b/tests/TestSupport/testFiles/palette-signature.png differ diff --git a/tests/__snapshots__/BorderTest__it_can_add_a_border_to_an_image_with_data_set_dataset_imagick__([50,_SpatieImageEnumsBorderType_Enum_(Overlay,_overlay),_333333])__1.png b/tests/__snapshots__/BorderTest__it_can_add_a_border_to_an_image_with_data_set_dataset_imagick__([50,_SpatieImageEnumsBorderType_Enum_(Overlay,_overlay),_333333])__1.png index 9219c55..ffdc1c9 100644 Binary files a/tests/__snapshots__/BorderTest__it_can_add_a_border_to_an_image_with_data_set_dataset_imagick__([50,_SpatieImageEnumsBorderType_Enum_(Overlay,_overlay),_333333])__1.png and b/tests/__snapshots__/BorderTest__it_can_add_a_border_to_an_image_with_data_set_dataset_imagick__([50,_SpatieImageEnumsBorderType_Enum_(Overlay,_overlay),_333333])__1.png differ diff --git a/tests/__snapshots__/FitTest__it_can_fit_a_PNG_palette_image_with_transparency_and_preserve_the_signature_with_data_set_dataset_gd__1.png b/tests/__snapshots__/FitTest__it_can_fit_a_PNG_palette_image_with_transparency_and_preserve_the_signature_with_data_set_dataset_gd__1.png new file mode 100644 index 0000000..3386b1e Binary files /dev/null and b/tests/__snapshots__/FitTest__it_can_fit_a_PNG_palette_image_with_transparency_and_preserve_the_signature_with_data_set_dataset_gd__1.png differ diff --git a/tests/__snapshots__/FitTest__it_can_fit_a_PNG_palette_image_with_transparency_and_preserve_the_signature_with_data_set_dataset_imagick__1.png b/tests/__snapshots__/FitTest__it_can_fit_a_PNG_palette_image_with_transparency_and_preserve_the_signature_with_data_set_dataset_imagick__1.png new file mode 100644 index 0000000..b51b9a7 Binary files /dev/null and b/tests/__snapshots__/FitTest__it_can_fit_a_PNG_palette_image_with_transparency_and_preserve_the_signature_with_data_set_dataset_imagick__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_angle_10__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_angle_10__1.png index d19ebf5..ae4c8e5 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_angle_10__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_angle_10__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_blue__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_blue__1.png index efdb499..b86efe3 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_blue__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_blue__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_100__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_100__1.png index e10dc76..6da54b9 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_100__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_100__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_30__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_30__1.png index fb752e6..cd6dbc1 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_30__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_30__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_50__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_50__1.png index 88cb305..0e3c7b7 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_50__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_fontSize_50__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_red__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_red__1.png index 82ead9f..46be762 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_red__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_red__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_100__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_100__1.png index e3cd824..4ca6d5f 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_100__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_100__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_200__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_200__1.png index 27c6d6d..526fcce 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_200__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_200__1.png differ diff --git a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_300__1.png b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_300__1.png index d421a82..9f46050 100644 Binary files a/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_300__1.png and b/tests/__snapshots__/TextTest__it_can_insert_text_to_image_with_data_set_dataset_gd__dataset_width_300__1.png differ