The GmagickDraw::annotate() function is an inbuilt function in PHP which is used to draw the text on the image.
Syntax:
GmagickDraw GmagickDraw::annotate( float $x, float $y, string $text )
Parameters: This function accept three parameters as mentioned above and described below:
- $x: It specifies the x-coordinate of the text.
- $y: It specifies the y-coordinate of the text.
- $text: It specifies the text content.
Return Value: This function returns GmagickDraw object on success.
Exceptions: This function throws GmagickException on error.
Below given programs illustrate the GmagickDraw::annotate() function in PHP:
Used Image:
Program 1 (Adding text to a drawing):
<?php   // Create a new Gmagick object $gmagick = new Gmagick('neveropen.png');    // Create a GmagickDraw object $draw = new GmagickDraw();    // Set the color $draw->setFillColor('white');    // Function to draw rectangle $draw->rectangle(0, 0, 800, 400);    // Set the fill color $draw->setFillColor('red');    // Set the font size $draw->setfontsize(80);    // Annotate a text $draw->annotate(30, 120, 'neveropen');    // Use of drawimage function $gmagick->drawImage($draw);    // Display the output image header("Content-Type: image/png"); echo $gmagick->getImageBlob(); ?> |
Output:
Program 2 (Adding text to a image):
<?php   // Create a new Gmagick object $gmagick = new Gmagick('neveropen.png');     // Create a GmagickDraw object $draw = new GmagickDraw();     // Set the fill color $draw->setFillColor('green');     // Set the font size $draw->setfontsize(30);     // Annotate a text $draw->annotate(100, 120,     'This line is drawn with annotate');     // Use of drawimage function $gmagick->drawImage($draw);     // Display the output image header("Content-Type: image/png"); echo $gmagick->getImageBlob(); ?> |
Output:
Reference: https://www.php.net/manual/en/gmagickdraw.annotate.php

