Tutorialspoint.dev

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 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:

<?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();
?>

Output:
setTextUnderColor

Program 2:

<?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();
?>

Output:
setTextUnderColor

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



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter