PHP | ImagickDraw pop() Function

The ImagickDraw::pop() function is an inbuilt function in PHP which is used to destroy the current ImagickDraw in the stack and returns the previously pushed ImagickDraw. For every pop() function there must have already been an equivalent push() function.

Syntax:

bool ImagickDraw::pop( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns TRUE on success.

Below programs illustrate the ImagickDraw::pop() 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 an image on imagick object
$imagick->newImage(800, 250, 'white');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the fill color
$draw->setFillColor('blue');
  
// Set the font size
$draw->setFontSize(70);
  
// Push 
$draw->push();
  
// Annotate a text
$draw->annotation(250, 70, 'Hello');
  
// Pop
$draw->pop();
  
// Set the fill color for new object
$draw->setFillColor('green');
  
// Annotate a text
$draw->annotation(250, 170, 'World');
  
// 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, 'white');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the stroke color
$draw->setStrokeColor('red');
  
// Set the fill color
$draw->setFillColor('blue');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Set the font size
$draw->setFontSize(72);
  
// Push 
$draw->push();
  
// Translate the object
$draw->translate(50, 50);
  
// Draw a circle
$draw->circle(250, 70, 250, 130);
  
// Pop because we want to draw a new
// circle with new properties.
$draw->pop();
  
// Set the stroke color for new object
$draw->setStrokeColor('violet');
  
// Set the fill color for new object
$draw->setFillColor('green');
  
// Draw a new circle
$draw->circle(250, 70, 250, 130);
  
// 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.pop.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.