Pop\Image\Imagick::drawArc PHP Метод

drawArc() публичный Метод

Method to add an arc to the image.
public drawArc ( integer $x, integer $y, integer $start, integer $end, integer $w, integer $h = null ) : Imagick
$x integer
$y integer
$start integer
$end integer
$w integer
$h integer
Результат Imagick
    public function drawArc($x, $y, $start, $end, $w, $h = null)
    {
        $wid = $w;
        $hgt = null === $h ? $w : $h;
        $draw = new \ImagickDraw();
        $draw->setFillColor($this->setColor($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 = array(array('x' => $x, 'y' => $y), array('x' => $x + $x1, 'y' => $y + $y1), array('x' => $x + $x2, 'y' => $y + $y2));
        $draw->polygon($points);
        $draw->ellipse($x, $y, $wid, $hgt, $start, $end);
        $this->resource->drawImage($draw);
        if (null !== $this->strokeWidth) {
            $draw = new \ImagickDraw();
            $draw->setFillColor($this->setColor($this->fillColor));
            $draw->setStrokeColor($this->setColor($this->strokeColor));
            $draw->setStrokeWidth(null === $this->strokeWidth ? 1 : $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->resource->drawImage($draw);
        }
        return $this;
    }

Usage Example

Пример #1
0
 public function testAddArc()
 {
     $i = new Imagick(__DIR__ . '/../tmp/test.jpg');
     $i->setStrokeColor(new Rgb(0, 0, 0))->setStrokeWidth(5)->drawArc(320, 240, 0, 120, 100, 100);
     $i->setBackgroundColor(new Rgb(255, 0, 0));
     $i->drawArc(320, 240, 0, 120, 100, 100);
     $i->setFillColor(new Rgb(255, 0, 0));
     $i->drawArc(320, 240, 0, 120, 100, 100);
     $this->assertEquals(640, $i->getWidth());
 }