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

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

Method to add a rectangle to the image.
public drawRectangle ( integer $x, integer $y, integer $w, integer $h = null ) : Gd
$x integer
$y integer
$w integer
$h integer
Результат Gd
    public function drawRectangle($x, $y, $w, $h = null)
    {
        $x2 = $x + $w;
        $y2 = $y + (null === $h ? $w : $h);
        // 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);
            }
        }
        imagefilledrectangle($this->resource, $x, $y, $x2, $y2, $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);
            imagerectangle($this->resource, $x, $y, $x2, $y2, $stroke);
        }
        $this->output = $this->resource;
        return $this;
    }

Usage Example

Пример #1
0
 public function testAddRectangle()
 {
     $i = new Gd(__DIR__ . '/../tmp/test.jpg');
     $i->setStrokeColor(new Rgb(0, 0, 0))->drawRectangle(10, 10, 100, 100);
     $i->setBackgroundColor(new Rgb(255, 0, 0));
     $i->drawRectangle(10, 10, 100, 100);
     $i->setFillColor(new Rgb(255, 0, 0));
     $i->drawRectangle(10, 10, 100, 100);
     $this->assertEquals(640, $i->getWidth());
 }