mirror of
https://github.com/Intervention/image.git
synced 2025-08-28 16:19:50 +02:00
Improve ContainModifier
This commit is contained in:
@@ -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(
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user