mirror of
https://github.com/Intervention/image.git
synced 2025-08-16 19:04:00 +02:00
Let draw methods accept object & callback input
This commit is contained in:
@@ -39,6 +39,19 @@ class Ellipse implements DrawableInterface
|
|||||||
return $this->pivot;
|
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
|
* Return pivot point of Ellipse
|
||||||
*
|
*
|
||||||
|
@@ -25,7 +25,8 @@ class CircleFactory implements DrawableFactoryInterface
|
|||||||
protected PointInterface $pivot = new Point(),
|
protected PointInterface $pivot = new Point(),
|
||||||
null|callable|Circle $init = null,
|
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)) {
|
if (is_callable($init)) {
|
||||||
$init($this);
|
$init($this);
|
||||||
|
@@ -25,7 +25,8 @@ class EllipseFactory implements DrawableFactoryInterface
|
|||||||
protected PointInterface $pivot = new Point(),
|
protected PointInterface $pivot = new Point(),
|
||||||
null|callable|Ellipse $init = null,
|
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)) {
|
if (is_callable($init)) {
|
||||||
$init($this);
|
$init($this);
|
||||||
|
@@ -26,6 +26,7 @@ class RectangleFactory implements DrawableFactoryInterface
|
|||||||
null|callable|Rectangle $init = null,
|
null|callable|Rectangle $init = null,
|
||||||
) {
|
) {
|
||||||
$this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot);
|
$this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot);
|
||||||
|
$this->rectangle->setPosition($pivot);
|
||||||
|
|
||||||
if (is_callable($init)) {
|
if (is_callable($init)) {
|
||||||
$init($this);
|
$init($this);
|
||||||
|
@@ -46,6 +46,19 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
|||||||
return $this->pivot;
|
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
|
* Implement iteration through all points of polygon
|
||||||
*
|
*
|
||||||
|
@@ -27,13 +27,18 @@ use Intervention\Image\Encoders\PngEncoder;
|
|||||||
use Intervention\Image\Encoders\TiffEncoder;
|
use Intervention\Image\Encoders\TiffEncoder;
|
||||||
use Intervention\Image\Encoders\WebpEncoder;
|
use Intervention\Image\Encoders\WebpEncoder;
|
||||||
use Intervention\Image\Exceptions\EncoderException;
|
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\BezierFactory;
|
||||||
use Intervention\Image\Geometry\Factories\CircleFactory;
|
use Intervention\Image\Geometry\Factories\CircleFactory;
|
||||||
use Intervention\Image\Geometry\Factories\EllipseFactory;
|
use Intervention\Image\Geometry\Factories\EllipseFactory;
|
||||||
use Intervention\Image\Geometry\Factories\LineFactory;
|
use Intervention\Image\Geometry\Factories\LineFactory;
|
||||||
use Intervention\Image\Geometry\Factories\PolygonFactory;
|
use Intervention\Image\Geometry\Factories\PolygonFactory;
|
||||||
use Intervention\Image\Geometry\Factories\RectangleFactory;
|
use Intervention\Image\Geometry\Factories\RectangleFactory;
|
||||||
|
use Intervention\Image\Geometry\Line;
|
||||||
use Intervention\Image\Geometry\Point;
|
use Intervention\Image\Geometry\Point;
|
||||||
|
use Intervention\Image\Geometry\Polygon;
|
||||||
use Intervention\Image\Geometry\Rectangle;
|
use Intervention\Image\Geometry\Rectangle;
|
||||||
use Intervention\Image\Interfaces\AnalyzerInterface;
|
use Intervention\Image\Interfaces\AnalyzerInterface;
|
||||||
use Intervention\Image\Interfaces\CollectionInterface;
|
use Intervention\Image\Interfaces\CollectionInterface;
|
||||||
@@ -825,7 +830,7 @@ final class Image implements ImageInterface
|
|||||||
*
|
*
|
||||||
* @see ImageInterface::drawEllipse()
|
* @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(
|
return $this->modify(
|
||||||
new DrawEllipseModifier(
|
new DrawEllipseModifier(
|
||||||
@@ -839,7 +844,7 @@ final class Image implements ImageInterface
|
|||||||
*
|
*
|
||||||
* @see ImageInterface::drawCircle()
|
* @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(
|
return $this->modify(
|
||||||
new DrawEllipseModifier(
|
new DrawEllipseModifier(
|
||||||
@@ -853,7 +858,7 @@ final class Image implements ImageInterface
|
|||||||
*
|
*
|
||||||
* @see ImageInterface::drawPolygon()
|
* @see ImageInterface::drawPolygon()
|
||||||
*/
|
*/
|
||||||
public function drawPolygon(callable $init): ImageInterface
|
public function drawPolygon(callable|Polygon $init): ImageInterface
|
||||||
{
|
{
|
||||||
return $this->modify(
|
return $this->modify(
|
||||||
new DrawPolygonModifier(
|
new DrawPolygonModifier(
|
||||||
@@ -867,7 +872,7 @@ final class Image implements ImageInterface
|
|||||||
*
|
*
|
||||||
* @see ImageInterface::drawLine()
|
* @see ImageInterface::drawLine()
|
||||||
*/
|
*/
|
||||||
public function drawLine(callable $init): ImageInterface
|
public function drawLine(callable|Line $init): ImageInterface
|
||||||
{
|
{
|
||||||
return $this->modify(
|
return $this->modify(
|
||||||
new DrawLineModifier(
|
new DrawLineModifier(
|
||||||
@@ -881,7 +886,7 @@ final class Image implements ImageInterface
|
|||||||
*
|
*
|
||||||
* @see ImageInterface::drawBezier()
|
* @see ImageInterface::drawBezier()
|
||||||
*/
|
*/
|
||||||
public function drawBezier(callable $init): ImageInterface
|
public function drawBezier(callable|Bezier $init): ImageInterface
|
||||||
{
|
{
|
||||||
return $this->modify(
|
return $this->modify(
|
||||||
new DrawBezierModifier(
|
new DrawBezierModifier(
|
||||||
|
@@ -9,6 +9,11 @@ use Intervention\Image\Encoders\AutoEncoder;
|
|||||||
use Intervention\Image\Exceptions\AnimationException;
|
use Intervention\Image\Exceptions\AnimationException;
|
||||||
use Intervention\Image\Exceptions\RuntimeException;
|
use Intervention\Image\Exceptions\RuntimeException;
|
||||||
use Intervention\Image\FileExtension;
|
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\MediaType;
|
||||||
use Intervention\Image\Origin;
|
use Intervention\Image\Origin;
|
||||||
use IteratorAggregate;
|
use IteratorAggregate;
|
||||||
@@ -711,11 +716,11 @@ interface ImageInterface extends IteratorAggregate, Countable
|
|||||||
* @link https://image.intervention.io/v3/modifying/drawing#drawing-ellipses
|
* @link https://image.intervention.io/v3/modifying/drawing#drawing-ellipses
|
||||||
* @param int $x
|
* @param int $x
|
||||||
* @param int $y
|
* @param int $y
|
||||||
* @param callable $init
|
* @param callable|Ellipse $init
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @return ImageInterface
|
* @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
|
* 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
|
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-circle
|
||||||
* @param int $x
|
* @param int $x
|
||||||
* @param int $y
|
* @param int $y
|
||||||
* @param callable $init
|
* @param callable|Circle $init
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @return ImageInterface
|
* @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
|
* Draw a polygon on the current image
|
||||||
*
|
*
|
||||||
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-polygon
|
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-polygon
|
||||||
* @param callable $init
|
* @param callable|Polygon $init
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @return ImageInterface
|
* @return ImageInterface
|
||||||
*/
|
*/
|
||||||
public function drawPolygon(callable $init): self;
|
public function drawPolygon(callable|Polygon $init): self;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw a line on the current image
|
* Draw a line on the current image
|
||||||
*
|
*
|
||||||
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-line
|
* @link https://image.intervention.io/v3/modifying/drawing#drawing-a-line
|
||||||
* @param callable $init
|
* @param callable|Line $init
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @return ImageInterface
|
* @return ImageInterface
|
||||||
*/
|
*/
|
||||||
public function drawLine(callable $init): self;
|
public function drawLine(callable|Line $init): self;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw a bezier curve on the current image
|
* Draw a bezier curve on the current image
|
||||||
*
|
*
|
||||||
* @link https://image.intervention.io/v3/modifying/drawing#draw-bezier-curves
|
* @link https://image.intervention.io/v3/modifying/drawing#draw-bezier-curves
|
||||||
* @param callable $init
|
* @param callable|Bezier $init
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @return ImageInterface
|
* @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
|
* Encode image to given media (mime) type. If no type is given the image
|
||||||
|
Reference in New Issue
Block a user