1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-19 04:01:30 +02:00

Fix random bugs

This commit is contained in:
Oliver Vogel
2023-09-30 10:56:30 +02:00
parent 1922fae048
commit 50f7ebce78
10 changed files with 62 additions and 35 deletions

View File

@@ -25,7 +25,7 @@ abstract class AbstractImage implements ImageInterface
use CanHandleInput;
use CanRunCallback;
public function eachFrame(callable $callback): self
public function eachFrame(callable $callback): ImageInterface
{
foreach ($this as $frame) {
$callback($frame);

View File

@@ -40,7 +40,7 @@ abstract class AbstractInputHandler
/**
* Try to decode the given input with each decoder of the the handler chain
*
* @param mixed $var
* @param mixed $input
* @return ImageInterface|ColorInterface
*/
public function handle($input): ImageInterface|ColorInterface

View File

@@ -13,7 +13,7 @@ class PadDownModifier extends PadModifier
$resize = $this->getResizeSize($image);
return $image->getSize()
->contain($resize->width(), $resize->height())
->contain($resize->getWidth(), $resize->getHeight())
->alignPivotTo($resize, $this->position);
}

View File

@@ -3,6 +3,8 @@
namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
use Intervention\Image\Drivers\Imagick\Color;
use Intervention\Image\Exceptions\TypeException;
use Intervention\Image\Geometry\Point;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
@@ -12,16 +14,14 @@ class DrawPixelModifier implements ModifierInterface
{
use CanHandleInput;
public function __construct(
protected Point $position,
protected $color
) {
public function __construct(protected Point $position, protected mixed $color)
{
//
}
public function apply(ImageInterface $image): ImageInterface
{
$color = $this->handleInput($this->color);
$color = $this->decodeColor();
$pixel = new ImagickDraw();
$pixel->setFillColor($color->getPixel());
$pixel->point($this->position->getX(), $this->position->getY());
@@ -30,4 +30,15 @@ class DrawPixelModifier implements ModifierInterface
$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;
}
}

View File

@@ -4,6 +4,8 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
use ImagickDraw;
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\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
@@ -44,4 +46,26 @@ class DrawPolygonModifier extends AbstractDrawModifier implements ModifierInterf
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;
}
}

View File

@@ -8,7 +8,6 @@ use Intervention\Image\Drivers\Imagick\Color;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Interfaces\ColorInterface;
class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInterface
{
@@ -37,7 +36,7 @@ class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInte
return $image;
}
protected function getBackgroundColor(): ColorInterface
protected function getBackgroundColor(): Color
{
$color = parent::getBackgroundColor();
if (!is_a($color, Color::class)) {
@@ -47,7 +46,7 @@ class DrawRectangleModifier extends AbstractDrawModifier implements ModifierInte
return $color;
}
protected function getBorderColor(): ColorInterface
protected function getBorderColor(): Color
{
$color = parent::getBorderColor();
if (!is_a($color, Color::class)) {

View File

@@ -13,7 +13,7 @@ class PadDownModifier extends PadModifier
$resize = $this->getResizeSize($image);
return $image->getSize()
->contain($resize->width(), $resize->height())
->contain($resize->getWidth(), $resize->getHeight())
->alignPivotTo($resize, $this->position);
}

View File

@@ -5,7 +5,6 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
use Intervention\Image\Drivers\Abstract\AbstractTextWriter;
use Intervention\Image\Drivers\Imagick\Font;
use Intervention\Image\Exceptions\FontException;
use Intervention\Image\Interfaces\FontInterface;
use Intervention\Image\Interfaces\ImageInterface;
class TextWriter extends AbstractTextWriter
@@ -23,27 +22,12 @@ class TextWriter extends AbstractTextWriter
$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;
}
protected function getFont(): FontInterface
protected function getFont(): Font
{
if (!is_a($this->font, Font::class)) {
throw new FontException('Font is not compatible to current driver.');

View File

@@ -177,8 +177,8 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface
* Calculate the relative position to another Size
* based on the pivot point settings of both sizes.
*
* @param Size $size
* @return Point
* @param SizeInterface $rectangle
* @return PointInterface
*/
public function getRelativePositionTo(SizeInterface $rectangle): PointInterface
{

View File

@@ -11,7 +11,7 @@ interface ImageInterface extends Traversable, Countable
/**
* Get frame of animation image at given position starting with zero
*
* @param int $key
* @param int $position
* @return null|FrameInterface
*/
public function getFrame(int $position = 0): ?FrameInterface;
@@ -24,6 +24,15 @@ interface ImageInterface extends Traversable, Countable
*/
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
*
@@ -118,7 +127,7 @@ interface ImageInterface extends Traversable, Countable
/**
* Turn image into a greyscale version
*
* @return void
* @return ImageInterface
*/
public function greyscale(): ImageInterface;
@@ -272,14 +281,14 @@ interface ImageInterface extends Traversable, Countable
/**
* Mirror the current image horizontally
*
* @return void
* @return ImageInterface
*/
public function flip(): ImageInterface;
/**
* Mirror the current image vertically
*
* @return void
* @return ImageInterface
*/
public function flop(): ImageInterface;