1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 09:10:21 +02:00

Change background color allocation for new GD cores

This commit is contained in:
Oliver Vogel
2023-11-11 09:15:06 +01:00
parent 6ebdf8a96f
commit 7009313197

View File

@@ -10,6 +10,9 @@ use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FactoryInterface; use Intervention\Image\Interfaces\FactoryInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanHandleInput; use Intervention\Image\Traits\CanHandleInput;
use Intervention\Image\Colors\Rgb\Channels\Blue;
use Intervention\Image\Colors\Rgb\Channels\Green;
use Intervention\Image\Colors\Rgb\Channels\Red;
class Factory implements FactoryInterface class Factory implements FactoryInterface
{ {
@@ -50,8 +53,8 @@ class Factory implements FactoryInterface
{ {
$this->frames->push( $this->frames->push(
$this->handleInput($source) $this->handleInput($source)
->frame() ->frame()
->setDelay($delay) ->setDelay($delay)
); );
return $this; return $this;
@@ -66,7 +69,18 @@ class Factory implements FactoryInterface
public function newCore(int $width, int $height, ?ColorInterface $background = null) public function newCore(int $width, int $height, ?ColorInterface $background = null)
{ {
$core = imagecreatetruecolor($width, $height); $core = imagecreatetruecolor($width, $height);
$color = $background ? $this->colorToInteger($background) : imagecolorallocatealpha($core, 0, 0, 0, 127);
$color = match (is_null($background)) {
true => imagecolorallocatealpha($core, 0, 0, 0, 127),
default => imagecolorallocatealpha(
$core,
$background->channel(Red::class)->value(),
$background->channel(Green::class)->value(),
$background->channel(Blue::class)->value(),
127
),
};
imagefill($core, 0, 0, $color); imagefill($core, 0, 0, $color);
imagesavealpha($core, true); imagesavealpha($core, true);