mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 12:11:26 +02:00
Fix random bugs
This commit is contained in:
@@ -25,7 +25,7 @@ abstract class AbstractImage implements ImageInterface
|
|||||||
use CanHandleInput;
|
use CanHandleInput;
|
||||||
use CanRunCallback;
|
use CanRunCallback;
|
||||||
|
|
||||||
public function eachFrame(callable $callback): self
|
public function eachFrame(callable $callback): ImageInterface
|
||||||
{
|
{
|
||||||
foreach ($this as $frame) {
|
foreach ($this as $frame) {
|
||||||
$callback($frame);
|
$callback($frame);
|
||||||
|
@@ -40,7 +40,7 @@ abstract class AbstractInputHandler
|
|||||||
/**
|
/**
|
||||||
* Try to decode the given input with each decoder of the the handler chain
|
* Try to decode the given input with each decoder of the the handler chain
|
||||||
*
|
*
|
||||||
* @param mixed $var
|
* @param mixed $input
|
||||||
* @return ImageInterface|ColorInterface
|
* @return ImageInterface|ColorInterface
|
||||||
*/
|
*/
|
||||||
public function handle($input): ImageInterface|ColorInterface
|
public function handle($input): ImageInterface|ColorInterface
|
||||||
|
@@ -13,7 +13,7 @@ class PadDownModifier extends PadModifier
|
|||||||
$resize = $this->getResizeSize($image);
|
$resize = $this->getResizeSize($image);
|
||||||
|
|
||||||
return $image->getSize()
|
return $image->getSize()
|
||||||
->contain($resize->width(), $resize->height())
|
->contain($resize->getWidth(), $resize->getHeight())
|
||||||
->alignPivotTo($resize, $this->position);
|
->alignPivotTo($resize, $this->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
use ImagickDraw;
|
use ImagickDraw;
|
||||||
|
use Intervention\Image\Drivers\Imagick\Color;
|
||||||
|
use Intervention\Image\Exceptions\TypeException;
|
||||||
use Intervention\Image\Geometry\Point;
|
use Intervention\Image\Geometry\Point;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
@@ -12,16 +14,14 @@ class DrawPixelModifier implements ModifierInterface
|
|||||||
{
|
{
|
||||||
use CanHandleInput;
|
use CanHandleInput;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(protected Point $position, protected mixed $color)
|
||||||
protected Point $position,
|
{
|
||||||
protected $color
|
|
||||||
) {
|
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$color = $this->handleInput($this->color);
|
$color = $this->decodeColor();
|
||||||
$pixel = new ImagickDraw();
|
$pixel = new ImagickDraw();
|
||||||
$pixel->setFillColor($color->getPixel());
|
$pixel->setFillColor($color->getPixel());
|
||||||
$pixel->point($this->position->getX(), $this->position->getY());
|
$pixel->point($this->position->getX(), $this->position->getY());
|
||||||
@@ -30,4 +30,15 @@ class DrawPixelModifier implements ModifierInterface
|
|||||||
$frame->getCore()->drawImage($pixel);
|
$frame->getCore()->drawImage($pixel);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function decodeColor(): Color
|
||||||
|
{
|
||||||
|
$color = $this->handleInput($this->color);
|
||||||
|
|
||||||
|
if (!is_a($color, Color::class)) {
|
||||||
|
throw new TypeException('Color is not compatible to current driver.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,8 @@ 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\Exceptions\TypeException;
|
||||||
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;
|
||||||
@@ -44,4 +46,26 @@ class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterf
|
|||||||
|
|
||||||
return $points;
|
return $points;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getBackgroundColor(): ?Color
|
||||||
|
{
|
||||||
|
$color = parent::getBackgroundColor();
|
||||||
|
|
||||||
|
if (!is_a($color, Color::class)) {
|
||||||
|
throw new TypeException('Color is not compatible to current driver.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $color;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getBorderColor(): ?Color
|
||||||
|
{
|
||||||
|
$color = parent::getBorderColor();
|
||||||
|
|
||||||
|
if (!is_a($color, Color::class)) {
|
||||||
|
throw new TypeException('Color is not compatible to current driver.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,6 @@ use Intervention\Image\Drivers\Imagick\Color;
|
|||||||
use Intervention\Image\Exceptions\DecoderException;
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
|
||||||
|
|
||||||
class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInterface
|
class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
@@ -37,7 +36,7 @@ class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInte
|
|||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBackgroundColor(): ColorInterface
|
protected function getBackgroundColor(): Color
|
||||||
{
|
{
|
||||||
$color = parent::getBackgroundColor();
|
$color = parent::getBackgroundColor();
|
||||||
if (!is_a($color, Color::class)) {
|
if (!is_a($color, Color::class)) {
|
||||||
@@ -47,7 +46,7 @@ class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInte
|
|||||||
return $color;
|
return $color;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBorderColor(): ColorInterface
|
protected function getBorderColor(): Color
|
||||||
{
|
{
|
||||||
$color = parent::getBorderColor();
|
$color = parent::getBorderColor();
|
||||||
if (!is_a($color, Color::class)) {
|
if (!is_a($color, Color::class)) {
|
||||||
|
@@ -13,7 +13,7 @@ class PadDownModifier extends PadModifier
|
|||||||
$resize = $this->getResizeSize($image);
|
$resize = $this->getResizeSize($image);
|
||||||
|
|
||||||
return $image->getSize()
|
return $image->getSize()
|
||||||
->contain($resize->width(), $resize->height())
|
->contain($resize->getWidth(), $resize->getHeight())
|
||||||
->alignPivotTo($resize, $this->position);
|
->alignPivotTo($resize, $this->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,7 +5,6 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
use Intervention\Image\Drivers\Abstract\AbstractTextWriter;
|
use Intervention\Image\Drivers\Abstract\AbstractTextWriter;
|
||||||
use Intervention\Image\Drivers\Imagick\Font;
|
use Intervention\Image\Drivers\Imagick\Font;
|
||||||
use Intervention\Image\Exceptions\FontException;
|
use Intervention\Image\Exceptions\FontException;
|
||||||
use Intervention\Image\Interfaces\FontInterface;
|
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
|
||||||
class TextWriter extends AbstractTextWriter
|
class TextWriter extends AbstractTextWriter
|
||||||
@@ -23,27 +22,12 @@ class TextWriter extends AbstractTextWriter
|
|||||||
$line
|
$line
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug
|
|
||||||
// $lines = new TextBlock($this->text);
|
|
||||||
// $box = $lines->getBoundingBox($this->font, $this->position);
|
|
||||||
// $points = [];
|
|
||||||
// foreach (array_chunk($box->toArray(), 2) as $p) {
|
|
||||||
// $points[] = ['x' => $p[0], 'y' => $p[1]];
|
|
||||||
// }
|
|
||||||
// $draw = new \ImagickDraw();
|
|
||||||
// $draw->setStrokeOpacity(1);
|
|
||||||
// $draw->setStrokeColor('black');
|
|
||||||
// $draw->setFillColor('transparent');
|
|
||||||
// $draw->polygon($points);
|
|
||||||
// $frame->getCore()->drawImage($draw);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFont(): FontInterface
|
protected function getFont(): Font
|
||||||
{
|
{
|
||||||
if (!is_a($this->font, Font::class)) {
|
if (!is_a($this->font, Font::class)) {
|
||||||
throw new FontException('Font is not compatible to current driver.');
|
throw new FontException('Font is not compatible to current driver.');
|
||||||
|
@@ -177,8 +177,8 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface
|
|||||||
* Calculate the relative position to another Size
|
* Calculate the relative position to another Size
|
||||||
* based on the pivot point settings of both sizes.
|
* based on the pivot point settings of both sizes.
|
||||||
*
|
*
|
||||||
* @param Size $size
|
* @param SizeInterface $rectangle
|
||||||
* @return Point
|
* @return PointInterface
|
||||||
*/
|
*/
|
||||||
public function getRelativePositionTo(SizeInterface $rectangle): PointInterface
|
public function getRelativePositionTo(SizeInterface $rectangle): PointInterface
|
||||||
{
|
{
|
||||||
|
@@ -11,7 +11,7 @@ interface ImageInterface extends Traversable, Countable
|
|||||||
/**
|
/**
|
||||||
* Get frame of animation image at given position starting with zero
|
* Get frame of animation image at given position starting with zero
|
||||||
*
|
*
|
||||||
* @param int $key
|
* @param int $position
|
||||||
* @return null|FrameInterface
|
* @return null|FrameInterface
|
||||||
*/
|
*/
|
||||||
public function getFrame(int $position = 0): ?FrameInterface;
|
public function getFrame(int $position = 0): ?FrameInterface;
|
||||||
@@ -24,6 +24,15 @@ interface ImageInterface extends Traversable, Countable
|
|||||||
*/
|
*/
|
||||||
public function addFrame(FrameInterface $frame): ImageInterface;
|
public function addFrame(FrameInterface $frame): ImageInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply given callback to each frame of the image
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return ImageInterface
|
||||||
|
*/
|
||||||
|
public function eachFrame(callable $callback): ImageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set loop count of animated image
|
* Set loop count of animated image
|
||||||
*
|
*
|
||||||
@@ -118,7 +127,7 @@ interface ImageInterface extends Traversable, Countable
|
|||||||
/**
|
/**
|
||||||
* Turn image into a greyscale version
|
* Turn image into a greyscale version
|
||||||
*
|
*
|
||||||
* @return void
|
* @return ImageInterface
|
||||||
*/
|
*/
|
||||||
public function greyscale(): ImageInterface;
|
public function greyscale(): ImageInterface;
|
||||||
|
|
||||||
@@ -272,14 +281,14 @@ interface ImageInterface extends Traversable, Countable
|
|||||||
/**
|
/**
|
||||||
* Mirror the current image horizontally
|
* Mirror the current image horizontally
|
||||||
*
|
*
|
||||||
* @return void
|
* @return ImageInterface
|
||||||
*/
|
*/
|
||||||
public function flip(): ImageInterface;
|
public function flip(): ImageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mirror the current image vertically
|
* Mirror the current image vertically
|
||||||
*
|
*
|
||||||
* @return void
|
* @return ImageInterface
|
||||||
*/
|
*/
|
||||||
public function flop(): ImageInterface;
|
public function flop(): ImageInterface;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user