PHP | ImagickDraw setVectorGraphics() Function
Last Updated :
17 Dec, 2019
The ImagickDraw::setVectorGraphics() function is an inbuilt function in PHP which is used to set the vector graphics associated with the specified ImagickDraw object. Vector graphics contains all the draw commands given to an ImagickDraw object. This function can be used to copy draw commands from one object to another or for editing the draw commands.
Syntax:
bool ImagickDraw::setVectorGraphics( string $xml )
Parameters: This function accepts a single parameter $xml which holds the vector graphics.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below programs illustrate the ImagickDraw::setVectorGraphics() function in PHP:
Program 1:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'black' );
$draw = new ImagickDraw();
$draw ->setFillColor( 'white' );
$draw ->setFontSize(80);
$draw ->annotation(60, 120, 'GeeksforGeeks' );
$vectorGraphics = $draw ->getVectorGraphics();
$draw2 = new ImagickDraw();
$draw2 ->setVectorGraphics( $vectorGraphics );
$imagick ->drawImage( $draw2 );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'black' );
$draw = new ImagickDraw();
$draw ->setFillColor( 'blue' );
$draw ->circle(200, 150, 190, 100);
$vectorGraphics = $draw ->getVectorGraphics();
$vectorGraphics = str_replace ( "'#00000000FFFF'" ,
"'#FFFF00000000'" , $vectorGraphics );
$draw ->setVectorGraphics( $vectorGraphics );
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickdraw.setvectorgraphics.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...