1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-20 04:31:24 +02:00

Add background parameter to FactoryInterface::newCore()

This commit is contained in:
Oliver Vogel
2023-11-05 10:02:10 +01:00
parent b29f0d3329
commit 27c47ae502
3 changed files with 20 additions and 7 deletions

View File

@@ -5,6 +5,8 @@ namespace Intervention\Image\Drivers\Gd;
use Intervention\Image\Collection;
use Intervention\Image\Drivers\Gd\Frame;
use Intervention\Image\Drivers\Gd\Image;
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FactoryInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanHandleInput;
@@ -12,6 +14,7 @@ use Intervention\Image\Traits\CanHandleInput;
class Factory implements FactoryInterface
{
use CanHandleInput;
use CanHandleColors;
/**
* {@inheritdoc}
@@ -60,10 +63,10 @@ class Factory implements FactoryInterface
return new Image($frames);
}
public function newCore(int $width, int $height)
public function newCore(int $width, int $height, ?ColorInterface $background = null)
{
$core = imagecreatetruecolor($width, $height);
$color = imagecolorallocatealpha($core, 0, 0, 0, 127);
$color = $background ? $this->colorToInteger($background) : imagecolorallocatealpha($core, 0, 0, 0, 127);
imagefill($core, 0, 0, $color);
imagesavealpha($core, true);

View File

@@ -4,7 +4,10 @@ namespace Intervention\Image\Drivers\Imagick;
use Imagick;
use ImagickPixel;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Drivers\Imagick\Image;
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\FactoryInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Traits\CanCheckType;
@@ -14,6 +17,7 @@ class Factory implements FactoryInterface
{
use CanHandleInput;
use CanCheckType;
use CanHandleColors;
/**
* {@inheritdoc}
@@ -66,10 +70,15 @@ class Factory implements FactoryInterface
*
* @see FactoryInterface::newCore()
*/
public function newCore(int $width, int $height)
public function newCore(int $width, int $height, ?ColorInterface $background = null)
{
$pixel = $background ? $this->colorToPixel(
$background,
new Colorspace()
) : new ImagickPixel('rgba(0, 0, 0, 0)');
$imagick = new Imagick();
$imagick->newImage($width, $height, new ImagickPixel('rgba(0, 0, 0, 0)'), 'png');
$imagick->newImage($width, $height, $pixel, 'png');
$imagick->setType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
$imagick->setColorspace(Imagick::COLORSPACE_RGB);

View File

@@ -24,8 +24,9 @@ interface FactoryInterface
/**
* Create new driver specific core image object
*
* @param int $width
* @param int $height
* @param int $width
* @param int $height
* @param null|ColorInterface $background
*/
public function newCore(int $width, int $height);
public function newCore(int $width, int $height, ?ColorInterface $background = null);
}