PHP | Imagick drawImage() Function

The Imagick::drawImage() function is an inbuilt function in PHP which is used to render the ImagickDraw object on the Imagick object. It is used to draw the image on the Imagick instance. We set an image matrix, parameters and the borders of the drawn image with the help of ImagickDraw methods and then render it using Imagick::drawImage() function.

Syntax:

bool Imagick::drawImage( ImagickDraw $draw )

Parameters: This function accepts single parameter $draw which holds the ImagickDraw instance to get the details about the image that is to be rendered on the screen.



Return Value: It returns True value when it is executed successfully.

Program: This program creates an image, set its dimensions and border properties and then render it on the screen.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Declare a string which to be drawn 
$geek = "GeeksforGeeks"
  
// Declare an Imagick object
$image = new Imagick();
  
// Declare an ImagickDraw object
$draw = new ImagickDraw(); 
  
// Set the color of Imagickdraw object
$draw->setFillColor(new ImagickPixel('Green')); 
  
// Set the font size of text
$draw->setFontSize(120); 
  
// Array representing the font metrics
$metrix = $image->queryFontMetrics($draw, $geek); 
  
// Set the position of text with respect
// to the border 
$draw->annotation(0, 100, $geek); 
  
// Create image of given size
$image->newImage(875, 150, new ImagickPixel('white')); 
  
// Use drawImage() function to draw the image
$image->drawImage($draw); 
  
// Set the border of image
$image->borderImage(new ImagickPixel('green'), 5, 5); 
  
// Set the image format
$image->setImageFormat('png'); 
  
header('Content-type: image/png');
  
// Display the image
echo $image;
  
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagick.drawimage.php



My Personal Notes arrow_drop_up

Im a final year MCA student at Panjab University, Chandigarh, one of the most prestigious university of India I am skilled in various aspects related to Web Development and AI I have worked as a freelancer at upwork and thus have knowledge on various aspects related to NLP, image processing and web

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.