diff --git a/src/Drivers/Gd/Modifiers/ContainModifier.php b/src/Drivers/Gd/Modifiers/ContainModifier.php index d3c91df5..7d5048df 100644 --- a/src/Drivers/Gd/Modifiers/ContainModifier.php +++ b/src/Drivers/Gd/Modifiers/ContainModifier.php @@ -2,6 +2,9 @@ namespace Intervention\Image\Drivers\Gd\Modifiers; +use Intervention\Image\Colors\Rgb\Channels\Blue; +use Intervention\Image\Colors\Rgb\Channels\Green; +use Intervention\Image\Colors\Rgb\Channels\Red; use Intervention\Image\Drivers\DriverModifier; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\FrameInterface; @@ -48,7 +51,13 @@ class ContainModifier extends DriverModifier // make image area transparent to keep transparency // even if background-color is set - $transparent = imagecolorallocatealpha($modified, 255, 0, 255, 127); + $transparent = imagecolorallocatealpha( + $modified, + $background->channel(Red::class)->value(), + $background->channel(Green::class)->value(), + $background->channel(Blue::class)->value(), + 127, + ); imagealphablending($modified, false); // do not blend / just overwrite imagecolortransparent($modified, $transparent); imagefilledrectangle( diff --git a/tests/Drivers/Gd/Modifiers/ContainModifierTest.php b/tests/Drivers/Gd/Modifiers/ContainModifierTest.php index 7a29aae2..ebcb1d64 100644 --- a/tests/Drivers/Gd/Modifiers/ContainModifierTest.php +++ b/tests/Drivers/Gd/Modifiers/ContainModifierTest.php @@ -23,7 +23,7 @@ class ContainModifierTest extends TestCase $this->assertEquals(200, $image->width()); $this->assertEquals(100, $image->height()); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(255, 0, 255, 0, $image->pickColor(140, 10)); + $this->assertColor(255, 255, 0, 0, $image->pickColor(140, 10)); // transparent $this->assertColor(255, 255, 0, 255, $image->pickColor(175, 10)); } }