From 99150c4e1d74abab1682fe73018003e0a657a042 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 6 Jan 2024 14:38:19 +0100 Subject: [PATCH] Change default background/blending colors --- src/Colors/Rgb/Decoders/TransparentColorDecoder.php | 2 +- src/Drivers/Gd/Driver.php | 2 +- src/Drivers/Imagick/Driver.php | 3 ++- tests/Drivers/Gd/InputHandlerTest.php | 2 +- tests/Drivers/Imagick/InputHandlerTest.php | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Colors/Rgb/Decoders/TransparentColorDecoder.php b/src/Colors/Rgb/Decoders/TransparentColorDecoder.php index a921e1a5..156a48a5 100644 --- a/src/Colors/Rgb/Decoders/TransparentColorDecoder.php +++ b/src/Colors/Rgb/Decoders/TransparentColorDecoder.php @@ -18,6 +18,6 @@ class TransparentColorDecoder extends HexColorDecoder throw new DecoderException('Unable to decode input'); } - return parent::decode('#ff00ff00'); + return parent::decode('#ffffff00'); } } diff --git a/src/Drivers/Gd/Driver.php b/src/Drivers/Gd/Driver.php index 8c53957c..d6b2230d 100644 --- a/src/Drivers/Gd/Driver.php +++ b/src/Drivers/Gd/Driver.php @@ -47,7 +47,7 @@ class Driver extends AbstractDriver // build new transparent GDImage $data = imagecreatetruecolor($width, $height); imagesavealpha($data, true); - $background = imagecolorallocatealpha($data, 255, 0, 255, 127); + $background = imagecolorallocatealpha($data, 255, 255, 255, 127); imagealphablending($data, false); imagefill($data, 0, 0, $background); imagecolortransparent($data, $background); diff --git a/src/Drivers/Imagick/Driver.php b/src/Drivers/Imagick/Driver.php index 99ea0449..209a46e0 100644 --- a/src/Drivers/Imagick/Driver.php +++ b/src/Drivers/Imagick/Driver.php @@ -46,7 +46,7 @@ class Driver extends AbstractDriver */ public function createImage(int $width, int $height): ImageInterface { - $background = new ImagickPixel('rgba(0, 0, 0, 0)'); + $background = new ImagickPixel('rgba(255, 255, 255, 0)'); $imagick = new Imagick(); $imagick->newImage($width, $height, $background, 'png'); @@ -54,6 +54,7 @@ class Driver extends AbstractDriver $imagick->setImageType(Imagick::IMGTYPE_UNDEFINED); $imagick->setColorspace(Imagick::COLORSPACE_SRGB); $imagick->setImageResolution(96, 96); + $imagick->setImageBackgroundColor($background); return new Image($this, new Core($imagick)); } diff --git a/tests/Drivers/Gd/InputHandlerTest.php b/tests/Drivers/Gd/InputHandlerTest.php index 1857b20e..4e8ca18c 100644 --- a/tests/Drivers/Gd/InputHandlerTest.php +++ b/tests/Drivers/Gd/InputHandlerTest.php @@ -138,6 +138,6 @@ class GdInputHandlerTest extends TestCase $input = 'transparent'; $result = $handler->handle($input); $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals([255, 0, 255, 0], $result->toArray()); + $this->assertEquals([255, 255, 255, 0], $result->toArray()); } } diff --git a/tests/Drivers/Imagick/InputHandlerTest.php b/tests/Drivers/Imagick/InputHandlerTest.php index 1175858a..ce3b3ed4 100644 --- a/tests/Drivers/Imagick/InputHandlerTest.php +++ b/tests/Drivers/Imagick/InputHandlerTest.php @@ -138,6 +138,6 @@ class InputHandlerTest extends TestCase $input = 'transparent'; $result = $handler->handle($input); $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals([255, 0, 255, 0], $result->toArray()); + $this->assertEquals([255, 255, 255, 0], $result->toArray()); } }