PHP | ImagickDraw getVectorGraphics() Function

The ImagickDraw::getVectorGraphics() function is an inbuilt function in PHP which is used to get string containing vector graphics. In simple words, it contains all the draw commands in the form of strings. It is also used to extract comments from a ImagickDraw object. It returns a large string containing so much unwanted data which can be trimmed using PHP substr() function.

Syntax:

string ImagickDraw::getVectorGraphics( void )

Parameters: This function doesn’t accepts any parameters.

Return Value: This function returns an string value containing the vector graphics.

Below programs illustrate the ImagickDraw::getVectorGraphics() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Get the vector graphics
$vectorGraphics = $draw->getVectorGraphics();
  
// Trim unwanted part
$vectorGraphics = substr($vectorGraphics, 807);
echo $vectorGraphics;
?>

chevron_right


Output:

Empty string because of no commands.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Add some draw commands
$draw->setTextUnderColor('green');
$draw->setFontSize(30);
$draw->line(30, 40, 100, 300);
  
// Get the vector graphics
$vectorGraphics = $draw->getVectorGraphics();
  
// Trim unwanted part
$vectorGraphics = substr($vectorGraphics, 806);
echo $vectorGraphics;
?>

chevron_right


Output:

text-undercolor '#000080800000' font-size 30 line 30 40 100 300

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Add comment
$draw->comment('GeeksforGeeks');
  
// Get the vector graphics as string
$graphics = $draw->getVectorGraphics();
  
// Get comment from vector graphics
$comment = substr($graphics, 807); 
echo $comment;
?>

chevron_right


Output:

GeeksforGeeks

Reference: https://www.php.net/manual/en/imagickdraw.getvectorgraphics.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.