/** * {@inheritdoc} */ public function line(PointInterface $start, PointInterface $end, Color $color, $thickness = 1) { try { $pixel = $this->getColor($color); $line = new \GmagickDraw(); $line->setstrokecolor($pixel); $line->setstrokewidth(max(1, (int) $thickness)); $line->setfillcolor($pixel); $line->line($start->getX(), $start->getY(), $end->getX(), $end->getY()); $this->gmagick->drawImage($line); $pixel = null; $line = null; } catch (\GmagickException $e) { throw new RuntimeException('Draw line operation failed', $e->getCode(), $e); } return $this; }
/** * Draw a pie slice on the image. * * @param int $x * @param int $y * @param int $start * @param int $end * @param int $w * @param int $h * @return Gmagick */ public function pie($x, $y, $start, $end, $w, $h = null) { $wid = $w; $hgt = null === $h ? $w : $h; $draw = new \GmagickDraw(); $draw->setFillColor($this->image->getColor($this->fillColor)); $x1 = $w * cos($start / 180 * pi()); $y1 = $h * sin($start / 180 * pi()); $x2 = $w * cos($end / 180 * pi()); $y2 = $h * sin($end / 180 * pi()); $points = [['x' => $x, 'y' => $y], ['x' => $x + $x1, 'y' => $y + $y1], ['x' => $x + $x2, 'y' => $y + $y2]]; $draw->polygon($points); $draw->ellipse($x, $y, $wid, $hgt, $start, $end); $this->image->resource()->drawImage($draw); if ($this->strokeWidth > 0) { $draw = new \GmagickDraw(); $draw->setFillColor($this->image->getColor($this->fillColor)); $draw->setStrokeColor($this->image->getColor($this->strokeColor)); $draw->setStrokeWidth($this->strokeWidth); $draw->ellipse($x, $y, $wid, $hgt, $start, $end); $draw->line($x, $y, $x + $x1, $y + $y1); $draw->line($x, $y, $x + $x2, $y + $y2); $this->image->resource()->drawImage($draw); } return $this; }