Friday, September 5, 2025
HomeLanguagesPHP | ImagickDraw pop() Function

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:




<?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();
?>


Output:

Program 2:




<?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();
?>


Output:

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS