| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace Intervention\Image\Imagick\Shapes;
- use Intervention\Image\Image;
- use Intervention\Image\Imagick\Color;
- class LineShape extends \Intervention\Image\AbstractShape
- {
- /**
- * Starting point x-coordinate of line
- *
- * @var int
- */
- public $x = 0;
- /**
- * Starting point y-coordinate of line
- *
- * @var int
- */
- public $y = 0;
- /**
- * Color of line
- *
- * @var string
- */
- public $color = '#000000';
- /**
- * Width of line in pixels
- *
- * @var int
- */
- public $width = 1;
- /**
- * Create new line shape instance
- *
- * @param int $x
- * @param int $y
- */
- public function __construct($x = null, $y = null)
- {
- $this->x = is_numeric($x) ? intval($x) : $this->x;
- $this->y = is_numeric($y) ? intval($y) : $this->y;
- }
- /**
- * Set current line color
- *
- * @param string $color
- * @return void
- */
- public function color($color)
- {
- $this->color = $color;
- }
- /**
- * Set current line width in pixels
- *
- * @param int $width
- * @return void
- */
- public function width($width)
- {
- $this->width = $width;
- }
- /**
- * Draw current instance of line to given endpoint on given image
- *
- * @param Image $image
- * @param int $x
- * @param int $y
- * @return boolean
- */
- public function applyToImage(Image $image, $x = 0, $y = 0)
- {
- $line = new \ImagickDraw;
- $color = new Color($this->color);
- $line->setStrokeColor($color->getPixel());
- $line->setStrokeWidth($this->width);
- $line->line($this->x, $this->y, $x, $y);
- $image->getCore()->drawImage($line);
- return true;
- }
- }
|