PolygonShape.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Intervention\Image\Gd\Shapes;
  3. use Intervention\Image\Image;
  4. use Intervention\Image\Gd\Color;
  5. class PolygonShape extends \Intervention\Image\AbstractShape
  6. {
  7. /**
  8. * Array of points of polygon
  9. *
  10. * @var int
  11. */
  12. public $points;
  13. /**
  14. * Create new polygon instance
  15. *
  16. * @param array $points
  17. */
  18. public function __construct($points)
  19. {
  20. $this->points = $points;
  21. }
  22. /**
  23. * Draw polygon on given image
  24. *
  25. * @param Image $image
  26. * @param int $x
  27. * @param int $y
  28. * @return boolean
  29. */
  30. public function applyToImage(Image $image, $x = 0, $y = 0)
  31. {
  32. $background = new Color($this->background);
  33. imagefilledpolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $background->getInt());
  34. if ($this->hasBorder()) {
  35. $border_color = new Color($this->border_color);
  36. imagesetthickness($image->getCore(), $this->border_width);
  37. imagepolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $border_color->getInt());
  38. }
  39. return true;
  40. }
  41. }