1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-11 08:24:02 +02:00
This commit is contained in:
Oliver Vogel
2023-10-21 09:44:53 +02:00
parent b5cbff3a89
commit 774e1b80a3
4 changed files with 13 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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