Thursday, October 23, 2025
HomeLanguagesPHP | Imagick annotateImage() Function

PHP | Imagick annotateImage() Function

The Imagick::annotateImage() function is an inbuilt function in PHP which is used to annotates an image with text. This function returns True on success.

Syntax:

bool Imagick::annotateImage( $draw_settings, $x, $y, $angle, $text )

Parameters: This function accepts five parameters as mentioned above and described below:

  • $draw_settings: This parameter is used to create an ImagickDraw object that contains settings for drawing the text.
  • $x: This parameter is set to horizontal offset in pixels to the left of text.
  • $y: This parameter is set to vertical offset in pixels to the baseline of text.
  • $angle: The angle at which to write the text.
  • $text: The string which needs to draw.

Return Value: This function returns True on success.

Below programs illustrate the Imagick::annotateImage() function in PHP:

Program 1:




<?php
/* Create some objects */
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel('white');
  
/* New image */
$image->newImage(800, 300, $pixel);
  
/* Black text */
$draw->setFillColor('green');
  
/* Font properties */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize( 30 );
  
/* Create text */
$image->annotateImage($draw, 30, 140, 0, 
   'neveropen: A computer science portal');
  
/* Give image a format */
$image->setImageFormat('png');
  
/* Output the image with headers */
header('Content-type: image/png');
echo $image;
  
?>


Output:
annonate Image

Program 2:




<?php
  
/* Create some objects */
$image = new Imagick();
$draw = new ImagickDraw();
$image = new Imagick(
   
/* Black text */
$draw->setFillColor('green');
   
/* Font properties */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize( 30 );
   
/* Create text */
$image->annotateImage($draw, 5, 120, 0, 
   'neveropen: A computer science portal');
   
/* Give image a format */
$image->setImageFormat('png');
   
/* Output the image with headers */
header('Content-type: image/png');
echo $image;
   
?>


Output:
annonate image

Related Articles:

Reference: http://php.net/manual/en/imagick.annotateimage.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS