File indexing completed on 2025-01-26 05:29:14

0001 <?php
0002 
0003 namespace Intervention\Image\Gd\Shapes;
0004 
0005 use Intervention\Image\Image;
0006 use Intervention\Image\Gd\Color;
0007 
0008 class LineShape extends \Intervention\Image\AbstractShape
0009 {
0010     /**
0011      * Starting point x-coordinate of line
0012      *
0013      * @var int
0014      */
0015     public $x = 0;
0016 
0017     /**
0018      * Starting point y-coordinate of line
0019      *
0020      * @var int
0021      */
0022     public $y = 0;
0023 
0024     /**
0025      * Color of line
0026      *
0027      * @var string
0028      */
0029     public $color = '#000000';
0030 
0031     /**
0032      * Width of line in pixels
0033      *
0034      * @var int
0035      */
0036     public $width = 1;
0037 
0038     /**
0039      * Create new line shape instance
0040      *
0041      * @param int $x
0042      * @param int $y
0043      */
0044     public function __construct($x = null, $y = null)
0045     {
0046         $this->x = is_numeric($x) ? intval($x) : $this->x;
0047         $this->y = is_numeric($y) ? intval($y) : $this->y;
0048     }
0049 
0050     /**
0051      * Set current line color
0052      *
0053      * @param  string $color
0054      * @return void
0055      */
0056     public function color($color)
0057     {
0058         $this->color = $color;
0059     }
0060 
0061     /**
0062      * Set current line width in pixels
0063      *
0064      * @param  int $width
0065      * @return void
0066      */
0067     public function width($width)
0068     {
0069         throw new \Intervention\Image\Exception\NotSupportedException(
0070             "Line width is not supported by GD driver."
0071         );
0072     }
0073 
0074     /**
0075      * Draw current instance of line to given endpoint on given image
0076      *
0077      * @param  Image   $image
0078      * @param  int     $x
0079      * @param  int     $y
0080      * @return boolean
0081      */
0082     public function applyToImage(Image $image, $x = 0, $y = 0)
0083     {
0084         $color = new Color($this->color);
0085         imageline($image->getCore(), $x, $y, $this->x, $this->y, $color->getInt());
0086 
0087         return true;
0088     }
0089 }