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

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

Method to add a rectangle to the image.
public drawRectangle ( integer $x, integer $y, integer $w, integer $h = null ) : Imagick
$x integer
$y integer
$w integer
$h integer
Результат Imagick
    public function drawRectangle($x, $y, $w, $h = null)
    {
        $x2 = $x + $w;
        $y2 = $y + (null === $h ? $w : $h);
        $draw = new \ImagickDraw();
        $draw->setFillColor($this->setColor($this->fillColor));
        if (null !== $this->strokeWidth) {
            $draw->setStrokeColor($this->setColor($this->strokeColor));
            $draw->setStrokeWidth(null === $this->strokeWidth ? 1 : $this->strokeWidth);
        }
        $draw->rectangle($x, $y, $x2, $y2);
        $this->resource->drawImage($draw);
        return $this;
    }

Usage Example

Пример #1
0
 public function testAddRectangle()
 {
     $i = new Imagick(__DIR__ . '/../tmp/test.jpg');
     $i->setStrokeColor(new Rgb(0, 0, 0))->setStrokeWidth(5)->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());
 }