LineShape.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Intervention\Image\Gd\Shapes;
  3. use Intervention\Image\Image;
  4. use Intervention\Image\Gd\Color;
  5. class LineShape extends \Intervention\Image\AbstractShape
  6. {
  7. /**
  8. * Starting point x-coordinate of line
  9. *
  10. * @var integer
  11. */
  12. public $x = 0;
  13. /**
  14. * Starting point y-coordinate of line
  15. *
  16. * @var integer
  17. */
  18. public $y = 0;
  19. /**
  20. * Color of line
  21. *
  22. * @var string
  23. */
  24. public $color = '#000000';
  25. /**
  26. * Width of line in pixels
  27. *
  28. * @var integer
  29. */
  30. public $width = 1;
  31. /**
  32. * Create new line shape instance
  33. *
  34. * @param integer $x
  35. * @param integer $y
  36. */
  37. public function __construct($x = null, $y = null)
  38. {
  39. $this->x = is_numeric($x) ? intval($x) : $this->x;
  40. $this->y = is_numeric($y) ? intval($y) : $this->y;
  41. }
  42. /**
  43. * Set current line color
  44. *
  45. * @param string $color
  46. * @return void
  47. */
  48. public function color($color)
  49. {
  50. $this->color = $color;
  51. }
  52. /**
  53. * Set current line width in pixels
  54. *
  55. * @param integer $width
  56. * @return void
  57. */
  58. public function width($width)
  59. {
  60. throw new \Intervention\Image\Exception\NotSupportedException(
  61. "Line width is not supported by GD driver."
  62. );
  63. }
  64. /**
  65. * Draw current instance of line to given endpoint on given image
  66. *
  67. * @param Image $image
  68. * @param integer $x
  69. * @param integer $y
  70. * @return boolean
  71. */
  72. public function applyToImage(Image $image, $x = 0, $y = 0)
  73. {
  74. $color = new Color($this->color);
  75. imageline($image->getCore(), $x, $y, $this->x, $this->y, $color->getInt());
  76. return true;
  77. }
  78. }