PHP | ImagickDraw setTextUnderColor() Function

The ImagickDraw::setTextUnderColor() function is an inbuilt function in PHP which is used to set the color of a background rectangle to place under text annotations.

Syntax:

bool ImagickDraw::setTextUnderColor( $under_color )

Parameters: This function accepts a single parameter $under_color which is used to hold the value of background color of the text.



Return Value: This function does not return any value.

Below programs illustrate the ImagickDraw::setTextUnderColor() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Create an ImagickDraw object 
$draw = new ImagickDraw();
  
// Set the image filled color 
$draw->setFillColor('white');
  
// Set the font size
$draw->setFontSize(68);
  
// Set the Text Under Color
$draw->setTextUnderColor('green');
  
// Set the text to be added
$draw->annotation(0, 190, "GeeksForGeeks");
  
// Set the font size
$draw->setFontSize(40);
  
// Set the text to be added
$draw->annotation(120, 290, "@sarthak_ishu11");
  
// Create new Imagick object 
$imagick = new Imagick();
  
// Set the image dimensions
$imagick->newImage(500, 400, 'lightgreen');
  
// Set the image format
$imagick->setImageFormat("png");
  
// Draw the image 
$imagick->drawImage($draw);
header("Content-Type: image/png");
  
// Display the image
echo $imagick->getImageBlob();
?>

chevron_right


Output:
setTextUnderColor

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
  
// Create an ImagickDraw object
$draw = new ImagickDraw();
  
// Set the image filled color 
$draw->setFillColor('white');
  
// Set the font size
$draw->setFontSize(68);
  
// Set the text to be added
$draw->annotation(0, 90, "GeeksForGeeks");
  
// Set the Text Under Color
$draw->setTextUnderColor('blue');
  
// Set the text to be added
$draw->annotation(0, 190, "GeeksForGeeks");
  
// Create new Imagick object 
$imagick = new Imagick();
  
// Set the image dimensions
$imagick->newImage(500, 300, 'lightgreen');
  
// Set the image format
$imagick->setImageFormat("png");
  
// Draw the image 
$imagick->drawImage($draw);
header("Content-Type: image/png");
  
// Display the image 
echo $imagick->getImageBlob();
?>

chevron_right


Output:
setTextUnderColor

Reference: http://php.net/manual/en/imagickdraw.settextundercolor.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.