diff --git a/src/Geometry/Ellipse.php b/src/Geometry/Ellipse.php index 731e52cc..cb7471ea 100644 --- a/src/Geometry/Ellipse.php +++ b/src/Geometry/Ellipse.php @@ -39,6 +39,19 @@ class Ellipse implements DrawableInterface return $this->pivot; } + /** + * Set position if ellipse + * + * @param PointInterface $position + * @return Ellipse + */ + public function setPosition(PointInterface $position): self + { + $this->pivot = $position; + + return $this; + } + /** * Return pivot point of Ellipse * diff --git a/src/Geometry/Factories/CircleFactory.php b/src/Geometry/Factories/CircleFactory.php index 83aa0336..ed4cad10 100644 --- a/src/Geometry/Factories/CircleFactory.php +++ b/src/Geometry/Factories/CircleFactory.php @@ -25,7 +25,8 @@ class CircleFactory implements DrawableFactoryInterface protected PointInterface $pivot = new Point(), null|callable|Circle $init = null, ) { - $this->circle = is_a($init, Circle::class) ? $init : new Circle(0, $pivot); + $this->circle = is_a($init, Circle::class) ? $init : new Circle(0); + $this->circle->setPosition($pivot); if (is_callable($init)) { $init($this); diff --git a/src/Geometry/Factories/EllipseFactory.php b/src/Geometry/Factories/EllipseFactory.php index 636575eb..8bb9298f 100644 --- a/src/Geometry/Factories/EllipseFactory.php +++ b/src/Geometry/Factories/EllipseFactory.php @@ -25,7 +25,8 @@ class EllipseFactory implements DrawableFactoryInterface protected PointInterface $pivot = new Point(), null|callable|Ellipse $init = null, ) { - $this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0, $pivot); + $this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0); + $this->ellipse->setPosition($pivot); if (is_callable($init)) { $init($this); diff --git a/src/Geometry/Factories/RectangleFactory.php b/src/Geometry/Factories/RectangleFactory.php index b563dd0f..d6402a29 100644 --- a/src/Geometry/Factories/RectangleFactory.php +++ b/src/Geometry/Factories/RectangleFactory.php @@ -26,6 +26,7 @@ class RectangleFactory implements DrawableFactoryInterface null|callable|Rectangle $init = null, ) { $this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot); + $this->rectangle->setPosition($pivot); if (is_callable($init)) { $init($this); diff --git a/src/Geometry/Polygon.php b/src/Geometry/Polygon.php index b1fe1301..f37a41b0 100644 --- a/src/Geometry/Polygon.php +++ b/src/Geometry/Polygon.php @@ -46,6 +46,19 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte return $this->pivot; } + /** + * Set pivot position of polygon + * + * @param PointInterface $position + * @return Polygon + */ + public function setPosition(PointInterface $position): self + { + $this->pivot = $position; + + return $this; + } + /** * Implement iteration through all points of polygon * diff --git a/src/Image.php b/src/Image.php index 8d11aef6..360c967e 100644 --- a/src/Image.php +++ b/src/Image.php @@ -27,13 +27,18 @@ use Intervention\Image\Encoders\PngEncoder; use Intervention\Image\Encoders\TiffEncoder; use Intervention\Image\Encoders\WebpEncoder; use Intervention\Image\Exceptions\EncoderException; +use Intervention\Image\Geometry\Bezier; +use Intervention\Image\Geometry\Circle; +use Intervention\Image\Geometry\Ellipse; use Intervention\Image\Geometry\Factories\BezierFactory; use Intervention\Image\Geometry\Factories\CircleFactory; use Intervention\Image\Geometry\Factories\EllipseFactory; use Intervention\Image\Geometry\Factories\LineFactory; use Intervention\Image\Geometry\Factories\PolygonFactory; use Intervention\Image\Geometry\Factories\RectangleFactory; +use Intervention\Image\Geometry\Line; use Intervention\Image\Geometry\Point; +use Intervention\Image\Geometry\Polygon; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\AnalyzerInterface; use Intervention\Image\Interfaces\CollectionInterface; @@ -825,7 +830,7 @@ final class Image implements ImageInterface * * @see ImageInterface::drawEllipse() */ - public function drawEllipse(int $x, int $y, callable $init): ImageInterface + public function drawEllipse(int $x, int $y, callable|Ellipse $init): ImageInterface { return $this->modify( new DrawEllipseModifier( @@ -839,7 +844,7 @@ final class Image implements ImageInterface * * @see ImageInterface::drawCircle() */ - public function drawCircle(int $x, int $y, callable $init): ImageInterface + public function drawCircle(int $x, int $y, callable|Circle $init): ImageInterface { return $this->modify( new DrawEllipseModifier( @@ -853,7 +858,7 @@ final class Image implements ImageInterface * * @see ImageInterface::drawPolygon() */ - public function drawPolygon(callable $init): ImageInterface + public function drawPolygon(callable|Polygon $init): ImageInterface { return $this->modify( new DrawPolygonModifier( @@ -867,7 +872,7 @@ final class Image implements ImageInterface * * @see ImageInterface::drawLine() */ - public function drawLine(callable $init): ImageInterface + public function drawLine(callable|Line $init): ImageInterface { return $this->modify( new DrawLineModifier( @@ -881,7 +886,7 @@ final class Image implements ImageInterface * * @see ImageInterface::drawBezier() */ - public function drawBezier(callable $init): ImageInterface + public function drawBezier(callable|Bezier $init): ImageInterface { return $this->modify( new DrawBezierModifier( diff --git a/src/Interfaces/ImageInterface.php b/src/Interfaces/ImageInterface.php index be0312cd..d400bc77 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -9,6 +9,11 @@ use Intervention\Image\Encoders\AutoEncoder; use Intervention\Image\Exceptions\AnimationException; use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\FileExtension; +use Intervention\Image\Geometry\Bezier; +use Intervention\Image\Geometry\Circle; +use Intervention\Image\Geometry\Ellipse; +use Intervention\Image\Geometry\Line; +use Intervention\Image\Geometry\Polygon; use Intervention\Image\MediaType; use Intervention\Image\Origin; use IteratorAggregate; @@ -711,11 +716,11 @@ interface ImageInterface extends IteratorAggregate, Countable * @link https://image.intervention.io/v3/modifying/drawing#drawing-ellipses * @param int $x * @param int $y - * @param callable $init + * @param callable|Ellipse $init * @throws RuntimeException * @return ImageInterface */ - public function drawEllipse(int $x, int $y, callable $init): self; + public function drawEllipse(int $x, int $y, callable|Ellipse $init): self; /** * Draw circle on the current image @@ -723,41 +728,41 @@ interface ImageInterface extends IteratorAggregate, Countable * @link https://image.intervention.io/v3/modifying/drawing#drawing-a-circle * @param int $x * @param int $y - * @param callable $init + * @param callable|Circle $init * @throws RuntimeException * @return ImageInterface */ - public function drawCircle(int $x, int $y, callable $init): self; + public function drawCircle(int $x, int $y, callable|Circle $init): self; /** * Draw a polygon on the current image * * @link https://image.intervention.io/v3/modifying/drawing#drawing-a-polygon - * @param callable $init + * @param callable|Polygon $init * @throws RuntimeException * @return ImageInterface */ - public function drawPolygon(callable $init): self; + public function drawPolygon(callable|Polygon $init): self; /** * Draw a line on the current image * * @link https://image.intervention.io/v3/modifying/drawing#drawing-a-line - * @param callable $init + * @param callable|Line $init * @throws RuntimeException * @return ImageInterface */ - public function drawLine(callable $init): self; + public function drawLine(callable|Line $init): self; /** * Draw a bezier curve on the current image * * @link https://image.intervention.io/v3/modifying/drawing#draw-bezier-curves - * @param callable $init + * @param callable|Bezier $init * @throws RuntimeException * @return ImageInterface */ - public function drawBezier(callable $init): self; + public function drawBezier(callable|Bezier $init): self; /** * Encode image to given media (mime) type. If no type is given the image