File indexing completed on 2025-03-02 05:33:38

0001 <?php
0002 
0003 namespace Intervention\Image\Gd\Shapes;
0004 
0005 use Intervention\Image\Image;
0006 use Intervention\Image\Gd\Color;
0007 
0008 class PolygonShape extends \Intervention\Image\AbstractShape
0009 {
0010     /**
0011      * Array of points of polygon
0012      *
0013      * @var int
0014      */
0015     public $points;
0016 
0017     /**
0018      * Create new polygon instance
0019      *
0020      * @param array $points
0021      */
0022     public function __construct($points)
0023     {
0024         $this->points = $points;
0025     }
0026 
0027     /**
0028      * Draw polygon on given image
0029      *
0030      * @param  Image   $image
0031      * @param  int     $x
0032      * @param  int     $y
0033      * @return boolean
0034      */
0035     public function applyToImage(Image $image, $x = 0, $y = 0)
0036     {
0037         $background = new Color($this->background);
0038         imagefilledpolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $background->getInt());
0039         
0040         if ($this->hasBorder()) {
0041             $border_color = new Color($this->border_color);
0042             imagesetthickness($image->getCore(), $this->border_width);
0043             imagepolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $border_color->getInt());
0044         }
0045     
0046         return true;
0047     }
0048 }