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:
- $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 call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | int() function
- p5.js | red() function
- p5.js | hue() function
- p5.js | min() function
- p5.js | cos() function
- D3.js | d3.hsl() Function
- p5.js | tan() function
- D3.js | d3.set.add() Function
- p5.js | sin() function
- D3.js | d3.set.has() Function
- p5.js | log() function
- PHP | pi( ) 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.



