Open In App

PHP | imagestring() Function

The imagestring() function is an inbuilt function in PHP which is used to draw the string horizontally. This function draws the string at given position.

Syntax:



bool imagestring( $image, $font, $x, $y, $string, $color )

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

Return Value: This function returns TRUE on success or FALSE on failure.



Below programs illustrate the imagestring() function in PHP.
Program 1:




<?php
   
// Create the size of image or blank image
$image = imagecreate(500, 300);
   
// Set the background color of image
$background_color = imagecolorallocate($image, 0, 153, 0);
   
// Set the text color of image
$text_color = imagecolorallocate($image, 255, 255, 255);
   
// Function to create image which contains string.
imagestring($image, 5, 180, 100,  "GeeksforGeeks", $text_color);
imagestring($image, 3, 160, 120,  "A computer science portal", $text_color);
   
header("Content-Type: image/png");
   
imagepng($image);
imagedestroy($image);
?>

Output:

Program 2:




<?php
  
// Create the size of image or blank image
$image = imagecreate(500, 300);
  
// Set the background color of image
$background_color = imagecolorallocate($image, 255, 255, 255);
  
// Set the text color of image
$text_color = imagecolorallocate($image, 0, 153, 0);
  
// Function to create image which contains string.
imagestring($image, 5, 50, 100, 
     "GeeksforGeeks: A computer science portal", $text_color);
  
header("Content-Type: image/png");
  
imagepng($image);
imagedestroy($image);
?>

Output:

Related Articles:

Reference: http://php.net/manual/en/function.imagestring.php


Article Tags :