Basic graphic concept in PHP | Image with Text






Images with text | PHP

(MSBTE) Q.Write a program to display Text in an Image in PHP.

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)

where,

ลžimage : The imagecreate or imagecreatetruecolor() function is used to create an image in a given size.

$font: This parameter is used to set the font size. The inbuilt font in Latin 2 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.

Example:
<?php 
header("Content-type:image/png");
$h=imagecreate(130,50);
$bg=imagecolorallocate($h,240,240,140);
$txt=imagecolorallocate($h, 0, 0, 0);
imagestring($h,5, 5, 18,"cwipedia.in",$txt);
imagepng($h);
 ?>
Output:




Comments