Thursday, October 9, 2025
HomeLanguagesPHP | GmagickDraw annotate() Function

PHP | GmagickDraw annotate() Function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS