imagestring() is a built-in function in PHP that draws a string horizontally.
bool imagestring($image, $font, $x, $y, $string, $color)
imagestring() accepts six different parameters − $image, $font, $x, $y, $string, and $color.
$image − The $image parameter uses imagecreatetruecolor() function to create a blank An image in a given size.
$font − The $font parameter is used to set the font size value to 1, 2, 3, 4 and 5
For built-in fonts.
$x - Maintains the font's position on the horizontal X-axis, top left corner.
$y - Maintains the font's position on the vertical Y-axis, top.
$string - The $string parameter holds the string to be written.
$color - This parameter holds the color of the image.
imagestring()Returns True on success and False on failure.
<?php // Create the size and image by using imagecreate() function. $img = imagecreate(700, 300); // Set the background color of the image $background_color = imagecolorallocate($img, 0, 0, 255); // Set the text color of the image $text_color = imagecolorallocate($img, 255, 255, 255); // Function to create an image that contains the string. imagestring($img, 50, 180, 150, "Tutorialspoint", $text_color); imagestring($img, 30, 160, 120, "Simply Easy Learning", $text_color); header("Content-Type: image/png"); imagepng($img); imagedestroy($img); ?>
<?php // Create the size of the image or blank image $img = imagecreate(700, 300); // Set the background color of the image $background_color = imagecolorallocate($img, 122, 122, 122); // Set the text color of the image $text_color = imagecolorallocate($img, 255, 255, 0); // Function to create an image that contains a string. imagestring($img, 10, 30, 60,"Tutorialspoint:Simply Easy Learning", $text_color); header("Content-Type: image/png"); imagepng($img); imagedestroy($img); ?>
The above is the detailed content of How to draw a text string image horizontally using the imagestring() function in PHP?. For more information, please follow other related articles on the PHP Chinese website!