
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to draw a text string image horizontally by using imagestring() function in PHP?
imagestring() is an inbuilt function in PHP that is used to draw a string horizontally.
Syntax
bool imagestring($image, $font, $x, $y, $string, $color)
Parameters
imagestring() accepts six different parameters − $image, $font, $x, $y, $string, and $color.
$image − The $image parameter uses imagecreatetruecolor() function to create a blank image in the given size.
$font − The $font parameter is used to set the font size values from 1, 2, 3, 4, and 5 for inbuilt fonts.
$x − Holds the position of the font in the horizontal X-axis, upper leftmost corner.
$y − Holds the position of the font in the vertical Y-axis, topmost corner.
$string − The $string parameter holds the string to be written.
$color − This parameter holds the color of the image.
Return Values
imagestring() returns True on success and False on failure.
Example 1
<?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); ?>
Output
Example 2
<?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); ?>
Output
- Related Articles
- How to draw a string vertically using imagestringup() function in PHP?
- How to draw a line using imageline() function in PHP?
- How to draw text On image in Android using Kotlin?
- How to draw an ellipse using imageellipse() function in PHP?
- How to draw text on Image in Android?
- How to draw a filled polygon using an imagefilledpolygon() function in PHP?
- How to align the text horizontally in a bar plot created by using ggplot2 in R?
- How to destroy an image in PHP using imagedestroy() function?
- How to ensure an image is a truecolor image using the imageistruecolor() function in PHP?
- How to apply a filter to an image using imagefilter() function in PHP?
- How to center a Text object horizontally on canvas using FabricJS?
- How to crop an image automatically using imagecropauto() function in PHP?
- How to draw a partial arc and fill it using imagefilledarc() function in PHP?
- How to rotate an image with a given angle using imagerotate() function in PHP?
- How to draw an open polygon using the imageopenpolygon() function n PHP?

Advertisements