Pop\Image\Gd::drawPolygon PHP Метод

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

Method to add a polygon to the image.
public drawPolygon ( array $points ) : Gd
$points array
Результат Gd
    public function drawPolygon($points)
    {
        $realPoints = array();
        foreach ($points as $coord) {
            if (isset($coord['x']) && isset($coord['y'])) {
                $realPoints[] = $coord['x'];
                $realPoints[] = $coord['y'];
            }
        }
        // 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);
            }
        }
        imagefilledpolygon($this->resource, $realPoints, count($points), $fill);
        // Create stroke, if applicable.
        if (null !== $this->strokeColor) {
            $stroke = $this->setColor($this->strokeColor);
            if (null === $this->strokeWidth) {
                $this->strokeWidth = 1;
            }
            imagesetthickness($this->resource, $this->strokeWidth);
            imagepolygon($this->resource, $realPoints, count($points), $stroke);
        }
        $this->output = $this->resource;
        return $this;
    }

Usage Example

Пример #1
0
 public function testAddPolygon()
 {
     $i = new Gd(__DIR__ . '/../tmp/test.jpg');
     $points = array(array('x' => 320, 'y' => 50), array('x' => 400, 'y' => 100), array('x' => 420, 'y' => 200), array('x' => 280, 'y' => 320), array('x' => 200, 'y' => 180));
     $i->setStrokeColor(new Rgb(0, 0, 0))->drawPolygon($points);
     $i->setBackgroundColor(new Rgb(255, 0, 0));
     $i->drawPolygon($points);
     $i->setFillColor(new Rgb(255, 0, 0));
     $i->drawPolygon($points);
     $this->assertEquals(640, $i->getWidth());
 }