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 Screenecho $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 imageecho $image->getImageBlob();?> |
Output:
Program 3:
<?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 text properties$draw->setFontSize(110);$draw->setFillColor('green'); // Apply the annotation() function$draw->annotation(20, 120, 'GeeksforGeeks'); // Set the text properties$draw->setFontSize(40);$draw->setFillColor('black'); // Apply the annotation() function$draw->annotation(70, 200, 'A computer science portal for geeks'); // Render the draw commands in the ImagickDraw object$imagick->drawImage($draw); // Show the output$imagick->setImageFormat("png");header("Content-Type: image/png");echo $imagick->getImageBlob();?> |
Output:
Reference: http://php.net/manual/en/imagickdraw.annotation.php


