1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-28 16:19:50 +02:00

Improve ContainModifier

This commit is contained in:
Oliver Vogel
2023-12-03 16:25:45 +01:00
parent d0b6ea059b
commit 8d9d3a0e12
2 changed files with 11 additions and 2 deletions

View File

@@ -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(

View File

@@ -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));
}
}