/** * {@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; }