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:
- $image: The imagecreatetruecolor() function is used to create a blank image in a given size.
- $font: This parameter is used to set the font size. Inbuilt font in latin2 encoding can be 1, 2, 3, 4, 5 or other font identifiers registered with imageloadfont() function.
- $x: This parameter is used to hold the x-coordinate of the upper left corner.
- $y: This parameter is used to hold the y-coordinate of the upper left corner.
- $string: This parameter is used to hold the string to be written.
- $color: This parameter is used to hold the color of image.
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
Recommended Posts:
- How to get the function name inside a function in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | imagecreatetruecolor() Function
- PHP | fpassthru( ) Function
- PHP | ImagickDraw getTextAlignment() Function
- PHP | Ds\Sequence last() Function
- PHP | Imagick floodFillPaintImage() Function
- Function to escape regex patterns before applied in PHP
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | GmagickPixel setcolor() function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- PHP | array_intersect_ukey() Function
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.

