PHP | ImagickDraw pushDefs() Function

The ImagickDraw::pushDefs() function is an inbuilt function in PHP which is used to indicate that following commands create named elements for early processing. These are usually used to define draw commands which should be safely processed earlier for the sake of efficiency. This command has no impact on the looks of the draw commands.

Syntax:

bool ImagickDraw::pushDefs( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns TRUE on success.

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



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
  
// Create a new imagickDraw object
$draw = new ImagickDraw();
  
// Set some properties of objects
$draw->setFillColor('cyan');
$draw->setStrokeWidth(2);
$draw->setFontSize(72);
  
// Create a definition
$draw->pushDefs();
$draw->setStrokeColor('white');
$draw->annotation(200, 100, 'GeeksforGeeks');
$draw->popDefs();
  
// Annotate a text
$draw->annotation(200, 170, 'GeeksforGeeks');
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
  
// Create a new imagickDraw object
$draw = new ImagickDraw();
  
// Create a definition
$draw->pushDefs();
$draw->setStrokeColor('white');
$draw->line(300, 200, 230, 23);
$draw->popDefs();
  
// Draw a line
$draw->line(230, 200, 310, 23);
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagickdraw.pushdefs.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.