Pop\Image\Gd::drawArc PHP Method

drawArc() public method

Method to add an arc to the image.
public drawArc ( integer $x, integer $y, integer $start, integer $end, integer $w, integer $h = null ) : Gd
$x integer
$y integer
$start integer
$end integer
$w integer
$h integer
return Gd
    public function drawArc($x, $y, $start, $end, $w, $h = null)
    {
        $wid = $w * 2;
        $hgt = (null === $h ? $w : $h) * 2;
        // Create an image resource.
        $this->createResource();
        // Set fill color and create rectangle.
        if (null === $this->fillColor && null === $this->backgroundColor) {
            $fill = $this->setColor(new Rgb(255, 255, 255));
        } else {
            if (null === $this->fillColor) {
                $fill = $this->setColor($this->backgroundColor);
            } else {
                $fill = $this->setColor($this->fillColor);
            }
        }
        imagefilledarc($this->resource, $x, $y, $wid, $hgt, $start, $end, $fill, IMG_ARC_PIE);
        // Create stroke, if applicable.
        if (null !== $this->strokeColor) {
            $x1 = $w * cos($start / 180 * pi());
            $y1 = $h * sin($start / 180 * pi());
            $x2 = $w * cos($end / 180 * pi());
            $y2 = $h * sin($end / 180 * pi());
            $stroke = $this->setColor($this->strokeColor);
            if (null === $this->strokeWidth) {
                $this->strokeWidth = 1;
            }
            imagesetthickness($this->resource, $this->strokeWidth);
            imagearc($this->resource, $x, $y, $wid, $hgt, $start, $end, $stroke);
            imageline($this->resource, $x, $y, $x + $x1, $y + $y1, $stroke);
            imageline($this->resource, $x, $y, $x + $x2, $y + $y2, $stroke);
        }
        $this->output = $this->resource;
        return $this;
    }

Usage Example

示例#1
0
 public function testAddArc()
 {
     $i = new Gd(__DIR__ . '/../tmp/test.jpg');
     $i->setStrokeColor(new Rgb(0, 0, 0))->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());
 }