Skip to content

Commit

Permalink
Fix bug with drawing (half) transparent colors with GD
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 20, 2023
1 parent 1831a4f commit 27833d2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Drivers/Gd/Modifiers/DrawEllipseModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -49,6 +51,7 @@ public function apply(ImageInterface $image): ImageInterface
)
);
} else {
imagealphablending($frame->native(), true);
imagefilledellipse(
$frame->native(),
$this->position()->x(),
Expand Down
1 change: 1 addition & 0 deletions src/Drivers/Gd/Modifiers/DrawLineModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/Drivers/Gd/Modifiers/DrawPixelModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function apply(ImageInterface $image): ImageInterface
);

foreach ($image as $frame) {
imagealphablending($frame->native(), true);
imagesetpixel(
$frame->native(),
$this->position->x(),
Expand Down
2 changes: 2 additions & 0 deletions src/Drivers/Gd/Modifiers/DrawPolygonModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/Drivers/Gd/Modifiers/DrawRectangleModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 27833d2

Please sign in to comment.