PHP | ImagickDraw annotation() Function
The ImagickDraw::annotation() function is an inbuilt function in PHP which is used to draw the text on the image.
Syntax:
bool ImagickDraw::annotation( $x, $y, $text )
Parameters: This function accepts three parameters as mentioned above and described below:
- $x: This parameter is used to hold the value of x coordinate where text is to be drawn.
- $y: This parameter is used to hold the value of y coordinate where text is to be drawn.
- $text: This parameter is used to hold the value of string to draw on the image.
Return Value: This function does not return an value.
Below programs illustrates the ImagickDraw::annotation() function in PHP:
Program 1:
<?php // Create an ImagickDraw Object $draw = new ImagickDraw(); // Set Fill Color $draw->setFillColor('white'); // Set FOnt Size $draw->setFontSize(20); // Set Text $draw->annotation(5, 75, "Geeksforgeeks!"); $draw->annotation(150, 75, "sarthak_ishu11"); // Create new Imagick Object $imagick = new Imagick(); $imagick->newImage(300, 160, 'green'); // Set Image Format $imagick->setImageFormat("png"); $imagick->drawImage($draw); header("Content-Type: image/png"); // Display Image on Screen echo $imagick->getImageBlob(); ?> |
Output:

Program 2:
<?php // Create an ImagickDraw Object $draw = new ImagickDraw(); // Set Stroke Opacity $draw->setStrokeOpacity(1); // Set Stroke Color $draw->setStrokeColor('Black'); // Set Fill Color $draw->setFillColor('Green'); // Set Stroke Width $draw->setStrokeWidth(3); // Define the points $points = [ ['x' => 40 * 5, 'y' => 10 * 5], ['x' => 20 * 5, 'y' => 20 * 5], ['x' => 70 * 5, 'y' => 50 * 5], ['x' => 40 * 5, 'y' => 10 * 5] ]; // Set the Font Size $draw->setFontSize(50); // Set the font family $draw->setFontFamily('Ubuntu-Mono'); // Set the text to be added $draw->annotation(30, 40, "GeeksForGeeks"); // Call Polyline Function $draw->polyline($points); // Create an Imagick Object $image = new Imagick(); // Create new Image $image->newImage(500, 300, 'white'); // Set Image Format $image->setImageFormat("png"); // Draw Image $image->drawImage($draw); header("Content-Type: image/png"); // Display the output image echo $image->getImageBlob(); ?> |
Output:

Reference: http://php.net/manual/en/imagickdraw.annotation.php
Recommended Posts:
- PHP | ImagickDraw arc() Function
- PHP | ImagickDraw setFontSize() Function
- PHP | ImagickDraw setFontFamily() Function
- PHP | ImagickDraw rectangle() Function
- PHP | ImagickDraw setFontWeight() Function
- PHP | ImagickDraw point() Function
- PHP | ImagickDraw line() Function
- PHP | ImagickDraw setFont() Function
- PHP | ImagickDraw bezier() Function
- PHP | ImagickDraw setFillColor() Function
- PHP | ImagickDraw setFontStyle() Function
- PHP | ImagickDraw getStrokeOpacity() Function
- PHP | ImagickDraw setViewbox() Function
- PHP | ImagickDraw rotate() Function
- PHP | ImagickDraw setStrokeColor() Function
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.



