diff --git a/src/Drivers/Gd/Traits/CanHandleColors.php b/src/Drivers/Gd/Traits/CanHandleColors.php index 938efdfc..799292df 100644 --- a/src/Drivers/Gd/Traits/CanHandleColors.php +++ b/src/Drivers/Gd/Traits/CanHandleColors.php @@ -3,8 +3,6 @@ namespace Intervention\Image\Drivers\Gd\Traits; use Intervention\Image\Colors\Rgb\Color; -use Intervention\Image\Colors\Rgb\Colorspace; -use Intervention\Image\Interfaces\ColorInterface; trait CanHandleColors { @@ -31,13 +29,11 @@ trait CanHandleColors /** * Transforms given color to the corresponding GD Library integer value * - * @param ColorInterface $color + * @param Color $color * @return int */ public function colorToInteger(Color $color): int { - $color = $color->convertTo(Colorspace::class); - $r = $color->red()->value(); $g = $color->green()->value(); $b = $color->blue()->value(); @@ -61,7 +57,7 @@ trait CanHandleColors * @param float|int $targetMax * @return float|int */ - private static function convertRange( + protected static function convertRange( float|int $input, float|int $min, float|int $max, diff --git a/src/Drivers/Imagick/Font.php b/src/Drivers/Imagick/Font.php index 2e8441bf..5e612c25 100644 --- a/src/Drivers/Imagick/Font.php +++ b/src/Drivers/Imagick/Font.php @@ -5,26 +5,29 @@ namespace Intervention\Image\Drivers\Imagick; use Imagick; use ImagickDraw; use Intervention\Image\Drivers\Abstract\AbstractFont; +use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors; use Intervention\Image\Exceptions\FontException; use Intervention\Image\Geometry\Polygon; use Intervention\Image\Geometry\Rectangle; class Font extends AbstractFont { + use CanHandleColors; + public function toImagickDraw(): ImagickDraw { if (!$this->hasFilename()) { throw new FontException('No font file specified.'); } - $color = $this->failIfNotClass($this->getColor(), Color::class); + $color = $this->colorToPixel($this->getColor()); $draw = new ImagickDraw(); $draw->setStrokeAntialias(true); $draw->setTextAntialias(true); $draw->setFont($this->getFilename()); $draw->setFontSize($this->getSize()); - $draw->setFillColor($color->getPixel()); + $draw->setFillColor($color); $draw->setTextAlignment(Imagick::ALIGN_LEFT); return $draw; diff --git a/src/Drivers/Imagick/Modifiers/PadModifier.php b/src/Drivers/Imagick/Modifiers/PadModifier.php index 3b0d38e2..fbfcbd23 100644 --- a/src/Drivers/Imagick/Modifiers/PadModifier.php +++ b/src/Drivers/Imagick/Modifiers/PadModifier.php @@ -5,7 +5,8 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers; use Imagick; use ImagickDraw; use Intervention\Image\Drivers\Abstract\Modifiers\AbstractPadModifier; -use Intervention\Image\Drivers\Imagick\Color; +use Intervention\Image\Colors\Rgb\Color; +use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ModifierInterface; use Intervention\Image\Interfaces\SizeInterface; @@ -16,12 +17,13 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface { use CanBuildNewImage; use CanHandleInput; + use CanHandleColors; public function apply(ImageInterface $image): ImageInterface { $resize = $this->getResizeSize($image); $crop = $this->getCropSize($image); - $background = $this->failIfNotClass($this->handleInput($this->background), Color::class); + $background = $this->handleInput($this->background); foreach ($image as $frame) { // resize current core @@ -59,7 +61,7 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface // draw background color on canvas $draw = new ImagickDraw(); - $draw->setFillColor($background->getPixel()); + $draw->setFillColor($this->colorToPixel($background)); $draw->rectangle(0, 0, $canvas->getImageWidth(), $canvas->getImageHeight()); $canvas->drawImage($draw); diff --git a/src/Drivers/Imagick/Traits/CanHandleColors.php b/src/Drivers/Imagick/Traits/CanHandleColors.php index 547030c1..adb50c41 100644 --- a/src/Drivers/Imagick/Traits/CanHandleColors.php +++ b/src/Drivers/Imagick/Traits/CanHandleColors.php @@ -13,7 +13,7 @@ trait CanHandleColors /** * Transforms ImagickPixel to own color object * - * @param int $value + * @param ImagickPixel $pixel * @return ColorInterface */ public function colorFromPixel(ImagickPixel $pixel): ColorInterface