PHP | GmagickDraw annotate() Function
Last Updated :
21 Jan, 2020
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
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$draw = new GmagickDraw();
$draw ->setFillColor( 'white' );
$draw ->rectangle(0, 0, 800, 400);
$draw ->setFillColor( 'red' );
$draw ->setfontsize(80);
$draw ->annotate(30, 120, 'GeeksforGeeks' );
$gmagick ->drawImage( $draw );
header( "Content-Type: image/png" );
echo $gmagick ->getImageBlob();
?>
|
Output:
Program 2 (Adding text to a image):
<?php
$gmagick = new Gmagick( 'geeksforgeeks.png' );
$draw = new GmagickDraw();
$draw ->setFillColor( 'green' );
$draw ->setfontsize(30);
$draw ->annotate(100, 120,
'This line is drawn with annotate' );
$gmagick ->drawImage( $draw );
header( "Content-Type: image/png" );
echo $gmagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/gmagickdraw.annotate.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...