Here is an example of a bit more complex drawing operation using ImagickDraw. This example extends the ImagickDraw class to create a custom shape, in this case a flower. That flower is then rendered to a canvas.
I like to keep it short with the descriptions, here's the code:
PHP:
-
<?php
-
-
class Flower extends ImagickDraw
-
{
-
private $ImagickPixel;
-
-
public function __construct()
-
{
-
$this->ImagickPixel = new ImagickPixel();
-
}
-
-
public function drawFlower()
-
{
-
$this->createStraw();
-
$this->createPetals();
-
$this->createLeafs();
-
}
-
-
private function createPetals()
-
{
-
$this->ImagickPixel->setColor( 'red' );
-
$this->setFillColor( $this->ImagickPixel );
-
-
$this->ImagickPixel->setColor( 'black' );
-
$this->setStrokeColor( $this->ImagickPixel );
-
$this->setStrokeWidth( 0.5 );
-
-
$this->circle( 40, 90, 70, 110 );
-
$this->circle( 85, 50, 115, 70 );
-
$this->circle( 125, 90, 155, 110 );
-
$this->circle( 85, 130, 115, 150 );
-
-
$this->ImagickPixel->setColor( 'white' );
-
$this->setFillColor( $this->ImagickPixel );
-
-
$this->circle( 85, 90, 115, 110 );
-
}
-
-
private function createStraw()
-
{
-
$this->ImagickPixel->setColor( 'transparent' );
-
$this->setFillColor( $this->ImagickPixel );
-
-
$this->ImagickPixel->setColor( 'green' );
-
$this->setStrokeColor( $this->ImagickPixel );
-
$this->setStrokeWidth( 4 );
-
-
)
-
);
-
}
-
-
private function createLeafs()
-
{
-
$this->ImagickPixel->setColor( 'green' );
-
$this->setFillColor( $this->ImagickPixel );
-
$this->setStrokeColor( $this->ImagickPixel );
-
-
)
-
);
-
-
)
-
);
-
}
-
}
-
-
$Flower = new Flower();
-
$Flower->drawFlower();
-
-
$Imagick = new Imagick();
-
$Imagick->newPseudoImage( 175, 500, "gradient:pink-white" );
-
$Imagick->setImageFormat( 'png' );
-
-
$Imagick->drawImage( $Flower );
-
-
echo $Imagick;
-
-
?>
I didn't have time to comment the code. But here's the result:

Pingback: Imagick blog » Blog Archive » ImagickDraw, more complex drawing