File indexing completed on 2025-01-26 05:29:14
0001 <?php 0002 0003 namespace Intervention\Image\Imagick\Shapes; 0004 0005 use Intervention\Image\Image; 0006 use Intervention\Image\Imagick\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 $this->width = $width; 0070 } 0071 0072 /** 0073 * Draw current instance of line to given endpoint on given image 0074 * 0075 * @param Image $image 0076 * @param int $x 0077 * @param int $y 0078 * @return boolean 0079 */ 0080 public function applyToImage(Image $image, $x = 0, $y = 0) 0081 { 0082 $line = new \ImagickDraw; 0083 0084 $color = new Color($this->color); 0085 $line->setStrokeColor($color->getPixel()); 0086 $line->setStrokeWidth($this->width); 0087 0088 $line->line($this->x, $this->y, $x, $y); 0089 $image->getCore()->drawImage($line); 0090 0091 return true; 0092 } 0093 }