Tuesday, July 28, 2026
HomeLanguagesPHP | ImagickDraw pushDefs() Function

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:




<?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, 'neveropen');
$draw->popDefs();
  
// Annotate a text
$draw->annotation(200, 170, 'neveropen');
  
// 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, '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();
?>


Output:

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

3 COMMENTS

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS