Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function polygon(array $coordinates, Color $color, $fill = false, $thickness = 1)
 {
     if (count($coordinates) < 3) {
         throw new InvalidArgumentException(sprintf('Polygon must consist of at least 3 coordinates, %d given', count($coordinates)));
     }
     $points = array_map(function (PointInterface $p) {
         return array('x' => $p->getX(), 'y' => $p->getY());
     }, $coordinates);
     try {
         $pixel = $this->getColor($color);
         $polygon = new \GmagickDraw();
         $polygon->setstrokecolor($pixel);
         $polygon->setstrokewidth(max(1, (int) $thickness));
         if ($fill) {
             $polygon->setfillcolor($pixel);
         } else {
             $polygon->setfillcolor('transparent');
         }
         $polygon->polygon($points);
         $this->gmagick->drawImage($polygon);
         $pixel = null;
         $polygon = null;
     } catch (\GmagickException $e) {
         throw new RuntimeException('Draw polygon operation failed', $e->getCode(), $e);
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Draw a polygon on the image.
  *
  * @param  array $points
  * @return Gmagick
  */
 public function polygon($points)
 {
     $draw = new \GmagickDraw();
     if (null !== $this->fillColor) {
         $draw->setFillColor($this->image->getColor($this->fillColor, $this->opacity));
     }
     if ($this->strokeWidth > 0) {
         $draw->setStrokeColor($this->image->getColor($this->strokeColor, $this->opacity));
         $draw->setStrokeWidth($this->strokeWidth);
     }
     $draw->polygon($points);
     $this->image->resource()->drawImage($draw);
     return $this;
 }