1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 05:01:20 +02:00

Refactor driver method

This commit is contained in:
Oliver Vogel
2023-11-25 14:30:59 +01:00
parent 12ecc4b81f
commit 516e963883
18 changed files with 47 additions and 79 deletions

View File

@@ -50,9 +50,4 @@ class Driver extends AbstractDriver
{
return new FontProcessor($font);
}
public function colorToNative(ColorInterface $color, ColorspaceInterface $colorspace): mixed
{
return (new ColorProcessor($colorspace))->colorToNative($color);
}
}

View File

@@ -19,9 +19,8 @@ class DrawEllipseModifier extends DrawModifier
$this->position()->y(),
$this->drawable->width() - 1,
$this->drawable->height() - 1,
$this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}
@@ -41,9 +40,8 @@ class DrawEllipseModifier extends DrawModifier
$this->drawable->height(),
0,
360,
$this->driver()->colorToNative(
$this->borderColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
)
);
} else {
@@ -53,9 +51,8 @@ class DrawEllipseModifier extends DrawModifier
$this->position()->y(),
$this->drawable->width(),
$this->drawable->height(),
$this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}

View File

@@ -16,9 +16,8 @@ class DrawLineModifier extends DrawModifier
$this->drawable->start()->y(),
$this->drawable->end()->x(),
$this->drawable->end()->y(),
$this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}

View File

@@ -9,9 +9,8 @@ class DrawPixelModifier extends DriverModifier
{
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->driver()->colorToNative(
$this->driver()->handleInput($this->color),
$image->colorspace()
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->color)
);
foreach ($image as $frame) {

View File

@@ -14,9 +14,8 @@ class DrawPolygonModifier extends DrawModifier
imagefilledpolygon(
$frame->native(),
$this->drawable->toArray(),
$this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}
@@ -26,9 +25,8 @@ class DrawPolygonModifier extends DrawModifier
imagepolygon(
$frame->native(),
$this->drawable->toArray(),
$this->driver()->colorToNative(
$this->borderColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
)
);
}

View File

@@ -18,9 +18,8 @@ class DrawRectangleModifier extends DrawModifier
$this->position()->y(),
$this->position()->x() + $this->drawable->width(),
$this->position()->y() + $this->drawable->height(),
$this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);
}
@@ -34,9 +33,8 @@ class DrawRectangleModifier extends DrawModifier
$this->position()->y(),
$this->position()->x() + $this->drawable->width(),
$this->position()->y() + $this->drawable->height(),
$this->driver()->colorToNative(
$this->borderColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
)
);
}

View File

@@ -2,7 +2,6 @@
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Drivers\DriverModifier;
use Intervention\Image\Drivers\Gd\Frame;
use Intervention\Image\Interfaces\ImageInterface;
@@ -11,7 +10,7 @@ class FillModifier extends DriverModifier
{
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->color();
$color = $this->color($image);
foreach ($image as $frame) {
if ($this->hasPosition()) {
@@ -24,11 +23,10 @@ class FillModifier extends DriverModifier
return $image;
}
private function color(): int
private function color(ImageInterface $image): int
{
return $this->driver()->colorToNative(
$this->driver()->handleInput($this->color),
new Colorspace()
return $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->color)
);
}

View File

@@ -2,7 +2,6 @@
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Drivers\DriverModifier;
use Intervention\Image\Drivers\Gd\FontProcessor;
use Intervention\Image\Interfaces\ImageInterface;
@@ -14,9 +13,8 @@ class TextModifier extends DriverModifier
$processor = $this->fontProcessor();
$lines = $processor->alignedTextBlock($this->position, $this->text);
$color = $this->driver()->colorToNative(
$this->driver()->handleInput($this->font->color()),
new Colorspace()
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->font->color())
);
foreach ($image as $frame) {

View File

@@ -48,9 +48,4 @@ class Driver extends AbstractDriver
{
return new FontProcessor($font);
}
public function colorToNative(ColorInterface $color, ColorspaceInterface $colorspace): mixed
{
return (new ColorProcessor($colorspace))->colorToNative($color);
}
}

View File

@@ -10,14 +10,12 @@ class DrawEllipseModifier extends DrawModifier
{
public function apply(ImageInterface $image): ImageInterface
{
$background_color = $this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
$border_color = $this->driver()->colorToNative(
$this->borderColor(),
$image->colorspace()
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
foreach ($image as $frame) {

View File

@@ -13,9 +13,8 @@ class DrawLineModifier extends DrawModifier
$drawing = new ImagickDraw();
$drawing->setStrokeWidth($this->drawable->width());
$drawing->setStrokeColor(
$this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
)
);

View File

@@ -10,9 +10,8 @@ class DrawPixelModifier extends DriverModifier
{
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->driver()->colorToNative(
$this->driver()->handleInput($this->color),
$image->colorspace()
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->color)
);
$pixel = new ImagickDraw();

View File

@@ -13,18 +13,16 @@ class DrawPolygonModifier extends DrawModifier
$drawing = new ImagickDraw();
if ($this->drawable->hasBackgroundColor()) {
$background_color = $this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace()
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
$drawing->setFillColor($background_color);
}
if ($this->drawable->hasBorder()) {
$border_color = $this->driver()->colorToNative(
$this->borderColor(),
$image->colorspace()
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
$drawing->setStrokeColor($border_color);

View File

@@ -12,14 +12,12 @@ class DrawRectangleModifier extends DrawModifier
{
$drawing = new ImagickDraw();
$background_color = $this->driver()->colorToNative(
$this->backgroundColor(),
$image->colorspace(),
$background_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->backgroundColor()
);
$border_color = $this->driver()->colorToNative(
$this->borderColor(),
$image->colorspace(),
$border_color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->borderColor()
);
$drawing->setFillColor($background_color);

View File

@@ -14,7 +14,9 @@ class FillModifier extends DriverModifier
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->driver()->handleInput($this->color);
$pixel = $this->driver()->colorToNative($color, $image->colorspace());
$pixel = $this->driver()
->colorProcessor($image->colorspace())
->colorToNative($color, $image->colorspace());
foreach ($image as $frame) {
if ($this->hasPosition()) {

View File

@@ -9,9 +9,8 @@ class RotateModifier extends DriverModifier
{
public function apply(ImageInterface $image): ImageInterface
{
$background = $this->driver()->colorToNative(
$this->driver()->handleInput($this->background),
$image->colorspace()
$background = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->background)
);
foreach ($image as $frame) {

View File

@@ -13,9 +13,8 @@ class TextModifier extends DriverModifier
$processor = $this->fontProcessor();
$lines = $processor->alignedTextBlock($this->position, $this->text);
$color = $this->driver()->colorToNative(
$this->driver()->handleInput($this->font->color()),
$image->colorspace()
$color = $this->driver()->colorProcessor($image->colorspace())->colorToNative(
$this->driver()->handleInput($this->font->color())
);
$draw = $processor->toImagickDraw($color);

View File

@@ -10,5 +10,4 @@ interface DriverInterface
public function handleInput(mixed $input): ImageInterface|ColorInterface;
public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface;
public function fontProcessor(FontInterface $font): FontProcessorInterface;
public function colorToNative(ColorInterface $color, ColorspaceInterface $colorspace): mixed;
}