mirror of
https://github.com/Intervention/image.git
synced 2025-08-27 07:44:30 +02:00
Adjust modifiers for new color model
This commit is contained in:
23
src/Colors/Rgb/Decoders/TransparentColorDecoder.php
Normal file
23
src/Colors/Rgb/Decoders/TransparentColorDecoder.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Colors\Rgb\Decoders;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
|
|
||||||
|
class TransparentColorDecoder extends HexColorDecoder
|
||||||
|
{
|
||||||
|
public function decode($input): ImageInterface|ColorInterface
|
||||||
|
{
|
||||||
|
if (! is_string($input)) {
|
||||||
|
throw new DecoderException('Unable to decode input');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strtolower($input) != 'transparent') {
|
||||||
|
throw new DecoderException('Unable to decode input');
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::decode('#00000000');
|
||||||
|
}
|
||||||
|
}
|
@@ -31,7 +31,7 @@ class AbstractDrawModifier
|
|||||||
return $this->drawable;
|
return $this->drawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBackgroundColor(): ?ColorInterface
|
protected function getBackgroundColor(): ColorInterface
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$color = $this->handleInput($this->drawable->getBackgroundColor());
|
$color = $this->handleInput($this->drawable->getBackgroundColor());
|
||||||
@@ -42,7 +42,7 @@ class AbstractDrawModifier
|
|||||||
return $color;
|
return $color;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBorderColor(): ?ColorInterface
|
protected function getBorderColor(): ColorInterface
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$color = $this->handleInput($this->drawable->getBorderColor());
|
$color = $this->handleInput($this->drawable->getBorderColor());
|
||||||
|
@@ -5,6 +5,7 @@ namespace Intervention\Image\Drivers\Gd;
|
|||||||
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
|
||||||
use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder;
|
||||||
use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder;
|
||||||
|
use Intervention\Image\Colors\Rgb\Decoders\TransparentColorDecoder;
|
||||||
use Intervention\Image\Drivers\Abstract\AbstractInputHandler;
|
use Intervention\Image\Drivers\Abstract\AbstractInputHandler;
|
||||||
use Intervention\Image\Drivers\Gd\Decoders\ImageObjectDecoder;
|
use Intervention\Image\Drivers\Gd\Decoders\ImageObjectDecoder;
|
||||||
use Intervention\Image\Drivers\Gd\Decoders\ColorObjectDecoder;
|
use Intervention\Image\Drivers\Gd\Decoders\ColorObjectDecoder;
|
||||||
@@ -21,7 +22,7 @@ class InputHandler extends AbstractInputHandler
|
|||||||
ColorObjectDecoder::class,
|
ColorObjectDecoder::class,
|
||||||
HexColorDecoder::class,
|
HexColorDecoder::class,
|
||||||
StringColorDecoder::class,
|
StringColorDecoder::class,
|
||||||
// Decoders\TransparentColorDecoder::class,
|
TransparentColorDecoder::class,
|
||||||
HtmlColornameDecoder::class,
|
HtmlColornameDecoder::class,
|
||||||
FilePointerImageDecoder::class,
|
FilePointerImageDecoder::class,
|
||||||
FilePathImageDecoder::class,
|
FilePathImageDecoder::class,
|
||||||
|
@@ -3,11 +3,14 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawEllipseModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawEllipseModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
return $image->eachFrame(function ($frame) {
|
return $image->eachFrame(function ($frame) {
|
||||||
@@ -20,7 +23,7 @@ class DrawEllipseModifier extends AbstractDrawModifier implements ModifierInterf
|
|||||||
$this->position->getY(),
|
$this->position->getY(),
|
||||||
$this->ellipse()->getWidth() - 1,
|
$this->ellipse()->getWidth() - 1,
|
||||||
$this->ellipse()->getHeight() - 1,
|
$this->ellipse()->getHeight() - 1,
|
||||||
$this->getBackgroundColor()->toInt()
|
$this->colorToInteger($this->getBackgroundColor())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +39,7 @@ class DrawEllipseModifier extends AbstractDrawModifier implements ModifierInterf
|
|||||||
$this->ellipse()->getHeight(),
|
$this->ellipse()->getHeight(),
|
||||||
0,
|
0,
|
||||||
360,
|
360,
|
||||||
$this->getBorderColor()->toInt()
|
$this->colorToInteger($this->getBorderColor())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
imagefilledellipse(
|
imagefilledellipse(
|
||||||
@@ -45,7 +48,7 @@ class DrawEllipseModifier extends AbstractDrawModifier implements ModifierInterf
|
|||||||
$this->position->getY(),
|
$this->position->getY(),
|
||||||
$this->ellipse()->getWidth(),
|
$this->ellipse()->getWidth(),
|
||||||
$this->ellipse()->getHeight(),
|
$this->ellipse()->getHeight(),
|
||||||
$this->getBackgroundColor()->toInt()
|
$this->colorToInteger($this->getBackgroundColor())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -3,11 +3,14 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawLineModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawLineModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
return $image->eachFrame(function ($frame) {
|
return $image->eachFrame(function ($frame) {
|
||||||
@@ -17,7 +20,7 @@ class DrawLineModifier extends AbstractDrawModifier implements ModifierInterface
|
|||||||
$this->line()->getStart()->getY(),
|
$this->line()->getStart()->getY(),
|
||||||
$this->line()->getEnd()->getX(),
|
$this->line()->getEnd()->getX(),
|
||||||
$this->line()->getEnd()->getY(),
|
$this->line()->getEnd()->getY(),
|
||||||
$this->getBackgroundColor()->toInt()
|
$this->colorToInteger($this->getBackgroundColor())
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -3,12 +3,15 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\DrawableInterface;
|
use Intervention\Image\Interfaces\DrawableInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected DrawableInterface $drawable
|
protected DrawableInterface $drawable
|
||||||
) {
|
) {
|
||||||
@@ -22,7 +25,7 @@ class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterf
|
|||||||
imagefilledpolygon(
|
imagefilledpolygon(
|
||||||
$frame->getCore(),
|
$frame->getCore(),
|
||||||
$this->polygon()->toArray(),
|
$this->polygon()->toArray(),
|
||||||
$this->getBackgroundColor()->toInt()
|
$this->colorToInteger($this->getBackgroundColor())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +35,7 @@ class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterf
|
|||||||
$frame->getCore(),
|
$frame->getCore(),
|
||||||
$this->polygon()->toArray(),
|
$this->polygon()->toArray(),
|
||||||
$this->polygon()->count(),
|
$this->polygon()->count(),
|
||||||
$this->getBorderColor()->toInt()
|
$this->colorToInteger($this->getBorderColor())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -3,11 +3,14 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$image->eachFrame(function ($frame) {
|
$image->eachFrame(function ($frame) {
|
||||||
@@ -19,7 +22,7 @@ class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInte
|
|||||||
$this->position->getY(),
|
$this->position->getY(),
|
||||||
$this->position->getX() + $this->rectangle()->bottomRightPoint()->getX(),
|
$this->position->getX() + $this->rectangle()->bottomRightPoint()->getX(),
|
||||||
$this->position->getY() + $this->rectangle()->bottomRightPoint()->getY(),
|
$this->position->getY() + $this->rectangle()->bottomRightPoint()->getY(),
|
||||||
$this->getBackgroundColor()->toInt()
|
$this->colorToInteger($this->getBackgroundColor())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +35,7 @@ class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInte
|
|||||||
$this->position->getY(),
|
$this->position->getY(),
|
||||||
$this->position->getX() + $this->rectangle()->bottomRightPoint()->getX(),
|
$this->position->getX() + $this->rectangle()->bottomRightPoint()->getX(),
|
||||||
$this->position->getY() + $this->rectangle()->bottomRightPoint()->getY(),
|
$this->position->getY() + $this->rectangle()->bottomRightPoint()->getY(),
|
||||||
$this->getBorderColor()->toInt()
|
$this->colorToInteger($this->getBorderColor())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractPadModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractPadModifier;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\FrameInterface;
|
use Intervention\Image\Interfaces\FrameInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
@@ -13,12 +13,13 @@ use Intervention\Image\Traits\CanHandleInput;
|
|||||||
class PadModifier extends AbstractPadModifier implements ModifierInterface
|
class PadModifier extends AbstractPadModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
use CanHandleInput;
|
use CanHandleInput;
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$crop = $this->getCropSize($image);
|
$crop = $this->getCropSize($image);
|
||||||
$resize = $this->getResizeSize($image);
|
$resize = $this->getResizeSize($image);
|
||||||
$background = $this->handleInput($this->background);
|
$background = $this->colorToInteger($this->handleInput($this->background));
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
$this->modify($frame, $crop, $resize, $background);
|
$this->modify($frame, $crop, $resize, $background);
|
||||||
@@ -31,7 +32,7 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface
|
|||||||
FrameInterface $frame,
|
FrameInterface $frame,
|
||||||
SizeInterface $crop,
|
SizeInterface $crop,
|
||||||
SizeInterface $resize,
|
SizeInterface $resize,
|
||||||
ColorInterface $background
|
int $background
|
||||||
): void {
|
): void {
|
||||||
// create new image
|
// create new image
|
||||||
$modified = imagecreatetruecolor(
|
$modified = imagecreatetruecolor(
|
||||||
@@ -39,7 +40,7 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface
|
|||||||
$resize->getHeight()
|
$resize->getHeight()
|
||||||
);
|
);
|
||||||
|
|
||||||
imagefill($modified, 0, 0, $background->toInt());
|
imagefill($modified, 0, 0, $background);
|
||||||
|
|
||||||
// get current image
|
// get current image
|
||||||
$current = $frame->getCore();
|
$current = $frame->getCore();
|
||||||
|
@@ -3,11 +3,14 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractRotateModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractRotateModifier;
|
||||||
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class RotateModifier extends AbstractRotateModifier implements ModifierInterface
|
class RotateModifier extends AbstractRotateModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
@@ -15,7 +18,7 @@ class RotateModifier extends AbstractRotateModifier implements ModifierInterface
|
|||||||
imagerotate(
|
imagerotate(
|
||||||
$frame->getCore(),
|
$frame->getCore(),
|
||||||
$this->rotationAngle(),
|
$this->rotationAngle(),
|
||||||
$this->backgroundColor()->toInt()
|
$this->colorToInteger($this->backgroundColor())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -4,14 +4,18 @@ namespace Intervention\Image\Drivers\Gd\Modifiers;
|
|||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\AbstractTextWriter;
|
use Intervention\Image\Drivers\Abstract\AbstractTextWriter;
|
||||||
use Intervention\Image\Drivers\Gd\Font;
|
use Intervention\Image\Drivers\Gd\Font;
|
||||||
|
use Intervention\Image\Drivers\Gd\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
|
||||||
class TextWriter extends AbstractTextWriter
|
class TextWriter extends AbstractTextWriter
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$lines = $this->getAlignedTextBlock();
|
$lines = $this->getAlignedTextBlock();
|
||||||
$font = $this->failIfNotClass($this->getFont(), Font::class);
|
$font = $this->failIfNotClass($this->getFont(), Font::class);
|
||||||
|
$color = $this->colorToInteger($font->getColor());
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
if ($this->font->hasFilename()) {
|
if ($this->font->hasFilename()) {
|
||||||
@@ -22,7 +26,7 @@ class TextWriter extends AbstractTextWriter
|
|||||||
$font->getAngle() * (-1),
|
$font->getAngle() * (-1),
|
||||||
$line->getPosition()->getX(),
|
$line->getPosition()->getX(),
|
||||||
$line->getPosition()->getY(),
|
$line->getPosition()->getY(),
|
||||||
$font->getColor()->toInt(),
|
$color,
|
||||||
$font->getFilename(),
|
$font->getFilename(),
|
||||||
$line
|
$line
|
||||||
);
|
);
|
||||||
@@ -35,7 +39,7 @@ class TextWriter extends AbstractTextWriter
|
|||||||
$line->getPosition()->getX(),
|
$line->getPosition()->getX(),
|
||||||
$line->getPosition()->getY(),
|
$line->getPosition()->getY(),
|
||||||
$line,
|
$line,
|
||||||
$this->font->getColor()->toInt()
|
$color
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ namespace Intervention\Image\Drivers\Imagick;
|
|||||||
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
|
||||||
use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder;
|
||||||
use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder;
|
||||||
|
use Intervention\Image\Colors\Rgb\Decoders\TransparentColorDecoder;
|
||||||
use Intervention\Image\Drivers\Abstract\AbstractInputHandler;
|
use Intervention\Image\Drivers\Abstract\AbstractInputHandler;
|
||||||
use Intervention\Image\Drivers\Imagick\Decoders\ImageObjectDecoder;
|
use Intervention\Image\Drivers\Imagick\Decoders\ImageObjectDecoder;
|
||||||
use Intervention\Image\Drivers\Imagick\Decoders\ColorObjectDecoder;
|
use Intervention\Image\Drivers\Imagick\Decoders\ColorObjectDecoder;
|
||||||
@@ -21,7 +22,7 @@ class InputHandler extends AbstractInputHandler
|
|||||||
ColorObjectDecoder::class,
|
ColorObjectDecoder::class,
|
||||||
HexColorDecoder::class,
|
HexColorDecoder::class,
|
||||||
StringColorDecoder::class,
|
StringColorDecoder::class,
|
||||||
// Decoders\TransparentColorDecoder::class,
|
TransparentColorDecoder::class,
|
||||||
HtmlColornameDecoder::class,
|
HtmlColornameDecoder::class,
|
||||||
FilePointerImageDecoder::class,
|
FilePointerImageDecoder::class,
|
||||||
FilePathImageDecoder::class,
|
FilePathImageDecoder::class,
|
||||||
|
@@ -4,24 +4,26 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
|
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawEllipseModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawEllipseModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$background_color = $this->failIfNotClass($this->getBackgroundColor(), Color::class);
|
$background_color = $this->colorToPixel($this->getBackgroundColor());
|
||||||
$border_color = $this->failIfNotClass($this->getBorderColor(), Color::class);
|
$border_color = $this->colorToPixel($this->getBorderColor());
|
||||||
|
|
||||||
return $image->eachFrame(function ($frame) use ($background_color, $border_color) {
|
return $image->eachFrame(function ($frame) use ($background_color, $border_color) {
|
||||||
$drawing = new ImagickDraw();
|
$drawing = new ImagickDraw();
|
||||||
$drawing->setFillColor($background_color->getPixel());
|
$drawing->setFillColor($background_color);
|
||||||
|
|
||||||
if ($this->ellipse()->hasBorder()) {
|
if ($this->ellipse()->hasBorder()) {
|
||||||
$drawing->setStrokeWidth($this->ellipse()->getBorderSize());
|
$drawing->setStrokeWidth($this->ellipse()->getBorderSize());
|
||||||
$drawing->setStrokeColor($border_color->getPixel());
|
$drawing->setStrokeColor($border_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
$drawing->ellipse(
|
$drawing->ellipse(
|
||||||
|
@@ -4,18 +4,22 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
|
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawLineModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawLineModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$drawing = new ImagickDraw();
|
$drawing = new ImagickDraw();
|
||||||
$color = $this->failIfNotClass($this->getBackgroundColor(), Color::class);
|
|
||||||
$drawing->setStrokeColor($color->getPixel());
|
|
||||||
$drawing->setStrokeWidth($this->line()->getWidth());
|
$drawing->setStrokeWidth($this->line()->getWidth());
|
||||||
|
$drawing->setStrokeColor(
|
||||||
|
$this->colorToPixel($this->getBackgroundColor())
|
||||||
|
);
|
||||||
|
|
||||||
$drawing->line(
|
$drawing->line(
|
||||||
$this->line()->getStart()->getX(),
|
$this->line()->getStart()->getX(),
|
||||||
$this->line()->getStart()->getY(),
|
$this->line()->getStart()->getY(),
|
||||||
|
@@ -4,13 +4,15 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
|
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\DrawableInterface;
|
use Intervention\Image\Interfaces\DrawableInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected DrawableInterface $drawable
|
protected DrawableInterface $drawable
|
||||||
) {
|
) {
|
||||||
@@ -20,15 +22,15 @@ class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterf
|
|||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$drawing = new ImagickDraw();
|
$drawing = new ImagickDraw();
|
||||||
$background_color = $this->failIfNotClass($this->getBackgroundColor(), Color::class);
|
$background_color = $this->colorToPixel($this->getBackgroundColor());
|
||||||
$border_color = $this->failIfNotClass($this->getBorderColor(), Color::class);
|
$border_color = $this->colorToPixel($this->getBorderColor());
|
||||||
|
|
||||||
if ($this->polygon()->hasBackgroundColor()) {
|
if ($this->polygon()->hasBackgroundColor()) {
|
||||||
$drawing->setFillColor($background_color->getPixel());
|
$drawing->setFillColor($background_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->polygon()->hasBorder()) {
|
if ($this->polygon()->hasBorder()) {
|
||||||
$drawing->setStrokeColor($border_color->getPixel());
|
$drawing->setStrokeColor($border_color);
|
||||||
$drawing->setStrokeWidth($this->polygon()->getBorderSize());
|
$drawing->setStrokeWidth($this->polygon()->getBorderSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,22 +4,23 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
|
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractDrawModifier;
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
// setup
|
|
||||||
$drawing = new ImagickDraw();
|
$drawing = new ImagickDraw();
|
||||||
$background_color = $this->failIfNotClass($this->getBackgroundColor(), Color::class);
|
$background_color = $this->colorToPixel($this->getBackgroundColor());
|
||||||
$border_color = $this->failIfNotClass($this->getBorderColor(), Color::class);
|
$border_color = $this->colorToPixel($this->getBorderColor());
|
||||||
|
|
||||||
$drawing->setFillColor($background_color->getPixel());
|
$drawing->setFillColor($background_color);
|
||||||
if ($this->rectangle()->hasBorder()) {
|
if ($this->rectangle()->hasBorder()) {
|
||||||
$drawing->setStrokeColor($border_color->getPixel());
|
$drawing->setStrokeColor($border_color);
|
||||||
$drawing->setStrokeWidth($this->rectangle()->getBorderSize());
|
$drawing->setStrokeWidth($this->rectangle()->getBorderSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,19 +3,19 @@
|
|||||||
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractRotateModifier;
|
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractRotateModifier;
|
||||||
use Intervention\Image\Drivers\Imagick\Color;
|
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
class RotateModifier extends AbstractRotateModifier implements ModifierInterface
|
class RotateModifier extends AbstractRotateModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$background = $this->failIfNotClass($this->backgroundColor(), Color::class);
|
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
$frame->getCore()->rotateImage(
|
$frame->getCore()->rotateImage(
|
||||||
$background->getPixel(),
|
$this->colorToPixel($this->backgroundColor()),
|
||||||
$this->rotationAngle()
|
$this->rotationAngle()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -105,11 +105,12 @@ class GdInputHandlerTest extends TestCase
|
|||||||
$this->assertEquals([10, 20, 30, 255], $result->toArray());
|
$this->assertEquals([10, 20, 30, 255], $result->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
// public function testHandleTransparent(): void
|
public function testHandleTransparent(): void
|
||||||
// {
|
{
|
||||||
// $handler = new InputHandler();
|
$handler = new InputHandler();
|
||||||
// $input = 'transparent';
|
$input = 'transparent';
|
||||||
// $result = $handler->handle($input);
|
$result = $handler->handle($input);
|
||||||
// $this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf(Color::class, $result);
|
||||||
// }
|
$this->assertEquals([0, 0, 0, 0], $result->toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -104,4 +104,13 @@ class InputHandlerTest extends TestCase
|
|||||||
$this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf(Color::class, $result);
|
||||||
$this->assertEquals([10, 20, 30, 255], $result->toArray());
|
$this->assertEquals([10, 20, 30, 255], $result->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHandleTransparent(): void
|
||||||
|
{
|
||||||
|
$handler = new InputHandler();
|
||||||
|
$input = 'transparent';
|
||||||
|
$result = $handler->handle($input);
|
||||||
|
$this->assertInstanceOf(Color::class, $result);
|
||||||
|
$this->assertEquals([0, 0, 0, 0], $result->toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user