1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 16:50:07 +02:00

Fill modifier filling

This commit is contained in:
Oliver Vogel
2021-10-31 07:55:33 +01:00
parent 4b7c182152
commit 9f885da391
3 changed files with 17 additions and 17 deletions

View File

@@ -6,11 +6,11 @@ use Intervention\Image\Drivers\Gd\InputHandler;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Traits\CanHandleInput;
use Intervention\Image\Traits\CanResolveDriverClass;
class FillModifier implements ModifierInterface
{
use CanHandleInput;
use CanResolveDriverClass;
public function __construct($filling, ?int $x = null, ?int $y = null)
{
@@ -21,7 +21,7 @@ class FillModifier implements ModifierInterface
{
$width = $image->getWidth();
$height = $image->getHeight();
$filling = $this->handleInput($this->filling);
$filling = $this->getApplicableFilling();
foreach ($image as $frame) {
imagefilledrectangle($frame->getCore(), 0, 0, $width - 1, $height - 1, $filling);
@@ -29,4 +29,9 @@ class FillModifier implements ModifierInterface
return $image;
}
protected function getApplicableFilling(): ColorInterface
{
return $this->resolveDriverClass('InputHandler')->handle($this->filling);
}
}

View File

@@ -4,13 +4,14 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use Intervention\Image\Drivers\Imagick\InputHandler;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Traits\CanHandleInput;
use Intervention\Image\Traits\CanResolveDriverClass;
class FillModifier implements ModifierInterface
{
use CanHandleInput;
use CanResolveDriverClass;
public function __construct($filling, ?int $x = null, ?int $y = null)
{
@@ -19,7 +20,7 @@ class FillModifier implements ModifierInterface
public function apply(ImageInterface $image): ImageInterface
{
$filling = $this->handleInput($this->filling);
$filling = $this->getApplicableFilling();
$draw = new ImagickDraw();
$draw->setFillColor($filling->getPixel());
@@ -31,4 +32,9 @@ class FillModifier implements ModifierInterface
return $image;
}
protected function getApplicableFilling(): ColorInterface
{
return $this->resolveDriverClass('InputHandler')->handle($this->filling);
}
}

View File

@@ -1,11 +0,0 @@
<?php
namespace Intervention\Image\Traits;
trait CanHandleInput
{
protected function handleInput($value)
{
return (new InputHandler())->handle($value);
}
}