1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-26 15:24:37 +02:00

Factory methods

This commit is contained in:
Oliver Vogel
2021-10-30 18:05:32 +00:00
parent e9a3e4a034
commit f043cebdd2
3 changed files with 60 additions and 0 deletions

View File

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

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

View 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)
]));
}
}