From 27833d225cbae3aa7eca0405e0adae9015073c7f Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Wed, 20 Dec 2023 16:31:52 +0100 Subject: [PATCH] Fix bug with drawing (half) transparent colors with GD --- src/Drivers/Gd/Modifiers/DrawEllipseModifier.php | 3 +++ src/Drivers/Gd/Modifiers/DrawLineModifier.php | 1 + src/Drivers/Gd/Modifiers/DrawPixelModifier.php | 1 + src/Drivers/Gd/Modifiers/DrawPolygonModifier.php | 2 ++ src/Drivers/Gd/Modifiers/DrawRectangleModifier.php | 2 ++ 5 files changed, 9 insertions(+) diff --git a/src/Drivers/Gd/Modifiers/DrawEllipseModifier.php b/src/Drivers/Gd/Modifiers/DrawEllipseModifier.php index 9f83e0dd..801ed764 100644 --- a/src/Drivers/Gd/Modifiers/DrawEllipseModifier.php +++ b/src/Drivers/Gd/Modifiers/DrawEllipseModifier.php @@ -15,6 +15,8 @@ public function apply(ImageInterface $image): ImageInterface { foreach ($image as $frame) { if ($this->drawable->hasBorder()) { + imagealphablending($frame->native(), true); + // slightly smaller ellipse to keep 1px bordered edges clean if ($this->drawable->hasBackgroundColor()) { imagefilledellipse( @@ -49,6 +51,7 @@ public function apply(ImageInterface $image): ImageInterface ) ); } else { + imagealphablending($frame->native(), true); imagefilledellipse( $frame->native(), $this->position()->x(), diff --git a/src/Drivers/Gd/Modifiers/DrawLineModifier.php b/src/Drivers/Gd/Modifiers/DrawLineModifier.php index 2d06131a..fe49ca7b 100644 --- a/src/Drivers/Gd/Modifiers/DrawLineModifier.php +++ b/src/Drivers/Gd/Modifiers/DrawLineModifier.php @@ -16,6 +16,7 @@ class DrawLineModifier extends AbstractDrawModifier public function apply(ImageInterface $image): ImageInterface { foreach ($image as $frame) { + imagealphablending($frame->native(), true); imageantialias($frame->native(), true); imageline( $frame->native(), diff --git a/src/Drivers/Gd/Modifiers/DrawPixelModifier.php b/src/Drivers/Gd/Modifiers/DrawPixelModifier.php index 5dbfec78..fec4cbdc 100644 --- a/src/Drivers/Gd/Modifiers/DrawPixelModifier.php +++ b/src/Drivers/Gd/Modifiers/DrawPixelModifier.php @@ -19,6 +19,7 @@ public function apply(ImageInterface $image): ImageInterface ); foreach ($image as $frame) { + imagealphablending($frame->native(), true); imagesetpixel( $frame->native(), $this->position->x(), diff --git a/src/Drivers/Gd/Modifiers/DrawPolygonModifier.php b/src/Drivers/Gd/Modifiers/DrawPolygonModifier.php index 3e9d0691..83506611 100644 --- a/src/Drivers/Gd/Modifiers/DrawPolygonModifier.php +++ b/src/Drivers/Gd/Modifiers/DrawPolygonModifier.php @@ -19,6 +19,7 @@ public function apply(ImageInterface $image): ImageInterface { foreach ($image as $frame) { if ($this->drawable->hasBackgroundColor()) { + imagealphablending($frame->native(), true); imagefilledpolygon( $frame->native(), $this->drawable->toArray(), @@ -29,6 +30,7 @@ public function apply(ImageInterface $image): ImageInterface } if ($this->drawable->hasBorder()) { + imagealphablending($frame->native(), true); imagesetthickness($frame->native(), $this->drawable->borderSize()); imagepolygon( $frame->native(), diff --git a/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php b/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php index 393b9e8f..0df6d144 100644 --- a/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php +++ b/src/Drivers/Gd/Modifiers/DrawRectangleModifier.php @@ -21,6 +21,7 @@ public function apply(ImageInterface $image): ImageInterface foreach ($image as $frame) { // draw background if ($this->drawable->hasBackgroundColor()) { + imagealphablending($frame->native(), true); imagefilledrectangle( $frame->native(), $this->position()->x(), @@ -35,6 +36,7 @@ public function apply(ImageInterface $image): ImageInterface // draw border if ($this->drawable->hasBorder()) { + imagealphablending($frame->native(), true); imagesetthickness($frame->native(), $this->drawable->borderSize()); imagerectangle( $frame->native(),