mirror of
https://github.com/Intervention/image.git
synced 2025-08-11 08:24:02 +02:00
Fix bugs
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd\Traits;
|
namespace Intervention\Image\Drivers\Gd\Traits;
|
||||||
|
|
||||||
use Intervention\Image\Colors\Rgb\Color;
|
use Intervention\Image\Colors\Rgb\Color;
|
||||||
use Intervention\Image\Colors\Rgb\Colorspace;
|
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
|
||||||
|
|
||||||
trait CanHandleColors
|
trait CanHandleColors
|
||||||
{
|
{
|
||||||
@@ -31,13 +29,11 @@ trait CanHandleColors
|
|||||||
/**
|
/**
|
||||||
* Transforms given color to the corresponding GD Library integer value
|
* Transforms given color to the corresponding GD Library integer value
|
||||||
*
|
*
|
||||||
* @param ColorInterface $color
|
* @param Color $color
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function colorToInteger(Color $color): int
|
public function colorToInteger(Color $color): int
|
||||||
{
|
{
|
||||||
$color = $color->convertTo(Colorspace::class);
|
|
||||||
|
|
||||||
$r = $color->red()->value();
|
$r = $color->red()->value();
|
||||||
$g = $color->green()->value();
|
$g = $color->green()->value();
|
||||||
$b = $color->blue()->value();
|
$b = $color->blue()->value();
|
||||||
@@ -61,7 +57,7 @@ trait CanHandleColors
|
|||||||
* @param float|int $targetMax
|
* @param float|int $targetMax
|
||||||
* @return float|int
|
* @return float|int
|
||||||
*/
|
*/
|
||||||
private static function convertRange(
|
protected static function convertRange(
|
||||||
float|int $input,
|
float|int $input,
|
||||||
float|int $min,
|
float|int $min,
|
||||||
float|int $max,
|
float|int $max,
|
||||||
|
@@ -5,26 +5,29 @@ namespace Intervention\Image\Drivers\Imagick;
|
|||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\AbstractFont;
|
use Intervention\Image\Drivers\Abstract\AbstractFont;
|
||||||
|
use Intervention\Image\Drivers\Imagick\Traits\CanHandleColors;
|
||||||
use Intervention\Image\Exceptions\FontException;
|
use Intervention\Image\Exceptions\FontException;
|
||||||
use Intervention\Image\Geometry\Polygon;
|
use Intervention\Image\Geometry\Polygon;
|
||||||
use Intervention\Image\Geometry\Rectangle;
|
use Intervention\Image\Geometry\Rectangle;
|
||||||
|
|
||||||
class Font extends AbstractFont
|
class Font extends AbstractFont
|
||||||
{
|
{
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function toImagickDraw(): ImagickDraw
|
public function toImagickDraw(): ImagickDraw
|
||||||
{
|
{
|
||||||
if (!$this->hasFilename()) {
|
if (!$this->hasFilename()) {
|
||||||
throw new FontException('No font file specified.');
|
throw new FontException('No font file specified.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$color = $this->failIfNotClass($this->getColor(), Color::class);
|
$color = $this->colorToPixel($this->getColor());
|
||||||
|
|
||||||
$draw = new ImagickDraw();
|
$draw = new ImagickDraw();
|
||||||
$draw->setStrokeAntialias(true);
|
$draw->setStrokeAntialias(true);
|
||||||
$draw->setTextAntialias(true);
|
$draw->setTextAntialias(true);
|
||||||
$draw->setFont($this->getFilename());
|
$draw->setFont($this->getFilename());
|
||||||
$draw->setFontSize($this->getSize());
|
$draw->setFontSize($this->getSize());
|
||||||
$draw->setFillColor($color->getPixel());
|
$draw->setFillColor($color);
|
||||||
$draw->setTextAlignment(Imagick::ALIGN_LEFT);
|
$draw->setTextAlignment(Imagick::ALIGN_LEFT);
|
||||||
|
|
||||||
return $draw;
|
return $draw;
|
||||||
|
@@ -5,7 +5,8 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
use Intervention\Image\Drivers\Abstract\Modifiers\AbstractPadModifier;
|
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\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
use Intervention\Image\Interfaces\SizeInterface;
|
use Intervention\Image\Interfaces\SizeInterface;
|
||||||
@@ -16,12 +17,13 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface
|
|||||||
{
|
{
|
||||||
use CanBuildNewImage;
|
use CanBuildNewImage;
|
||||||
use CanHandleInput;
|
use CanHandleInput;
|
||||||
|
use CanHandleColors;
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$resize = $this->getResizeSize($image);
|
$resize = $this->getResizeSize($image);
|
||||||
$crop = $this->getCropSize($image);
|
$crop = $this->getCropSize($image);
|
||||||
$background = $this->failIfNotClass($this->handleInput($this->background), Color::class);
|
$background = $this->handleInput($this->background);
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
// resize current core
|
// resize current core
|
||||||
@@ -59,7 +61,7 @@ class PadModifier extends AbstractPadModifier implements ModifierInterface
|
|||||||
|
|
||||||
// draw background color on canvas
|
// draw background color on canvas
|
||||||
$draw = new ImagickDraw();
|
$draw = new ImagickDraw();
|
||||||
$draw->setFillColor($background->getPixel());
|
$draw->setFillColor($this->colorToPixel($background));
|
||||||
$draw->rectangle(0, 0, $canvas->getImageWidth(), $canvas->getImageHeight());
|
$draw->rectangle(0, 0, $canvas->getImageWidth(), $canvas->getImageHeight());
|
||||||
$canvas->drawImage($draw);
|
$canvas->drawImage($draw);
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ trait CanHandleColors
|
|||||||
/**
|
/**
|
||||||
* Transforms ImagickPixel to own color object
|
* Transforms ImagickPixel to own color object
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param ImagickPixel $pixel
|
||||||
* @return ColorInterface
|
* @return ColorInterface
|
||||||
*/
|
*/
|
||||||
public function colorFromPixel(ImagickPixel $pixel): ColorInterface
|
public function colorFromPixel(ImagickPixel $pixel): ColorInterface
|
||||||
|
Reference in New Issue
Block a user