mirror of
https://github.com/Intervention/image.git
synced 2025-08-26 15:24:37 +02:00
Factory methods
This commit is contained in:
@@ -11,6 +11,9 @@ class ImageFactory implements FactoryInterface
|
||||
public function newImage(int $width, int $height): ImageInterface
|
||||
{
|
||||
$gd = imagecreatetruecolor($width, $height);
|
||||
$color = imagecolorallocatealpha($gd, 0, 0, 0, 127);
|
||||
imagefill($gd, 0, 0, $color);
|
||||
imagesavealpha($gd, true);
|
||||
|
||||
return new Image(new Collection([
|
||||
new Frame($gd)
|
||||
|
31
src/Drivers/Gd/Modifiers/FillModifier.php
Normal file
31
src/Drivers/Gd/Modifiers/FillModifier.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
|
||||
class FillModifier implements ModifierInterface
|
||||
{
|
||||
public function __construct($filling, int $x, int $y)
|
||||
{
|
||||
$this->filling = $filling;
|
||||
}
|
||||
|
||||
public function apply(ImageInterface $image): ImageInterface
|
||||
{
|
||||
foreach ($image as $frame) {
|
||||
$this->blurFrame($frame);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
protected function blurFrame(FrameInterface $frame): void
|
||||
{
|
||||
for ($i = 0; $i < $this->amount; $i++) {
|
||||
imagefilter($frame->getCore(), IMG_FILTER_GAUSSIAN_BLUR);
|
||||
}
|
||||
}
|
||||
}
|
26
src/Drivers/Imagick/ImageFactory.php
Normal file
26
src/Drivers/Imagick/ImageFactory.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Imagick;
|
||||
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Collection;
|
||||
use Intervention\Image\Drivers\Imagick\Color;
|
||||
use Intervention\Image\Interfaces\FactoryInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
|
||||
class ImageFactory implements FactoryInterface
|
||||
{
|
||||
public function newImage(int $width, int $height): ImageInterface
|
||||
{
|
||||
$imagick = new Imagick();
|
||||
$imagick->newImage($width, $height, new ImagickPixel('rgba(0, 0, 0, 0)'), 'png');
|
||||
$imagick->setType(Imagick::IMGTYPE_UNDEFINED);
|
||||
$imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
|
||||
$imagick->setColorspace(Imagick::COLORSPACE_UNDEFINED);
|
||||
|
||||
return new Image(new Collection([
|
||||
new Frame($imagick)
|
||||
]));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user