imagestring($source_image,$int_font,$int_x,$int_y,$text,$int_color)
$source_image : Image resource created before<?Php
header ("Content-type: image/jpg");
///// Create the image ////////
$im = @ImageCreate (100,40)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 204, 204, 204); // Assign background color
$text_color = ImageColorAllocate ($im, 51, 51, 255); // text color is given
ImageString($im,5,14,0,'PLUS2NET',$text_color); // Text added
ImageJpeg ($im); // image displayed
imagedestroy($im); // Memory allocation for the image is removed.
?>
Output is here
<img src=gd-imagestring-demo.php>
ImageString($im,5,14,0,'PLUS2NET',$text_color);
ImageString($im,5,0,0,'PLUS2NET',$text_color);
$font_height=imagefontheight(5);
$font_width=imagefontwidth(5);
We will use above functions to know height and width of the fonts used. Based on this value we can allign Text to Right or bottom of the image.
<?Php
header ("Content-type: image/jpg");
$height=40; // Canvas Height
$width=100; // Canvas Width
$font_width=imagefontwidth(5); // Width of each char used in text string
$text="PLUS2NET"; // Text string to be written on Image.
$no_text=strlen($text); // Number of chars in our text string.
$text_width=$no_text * $font_width; // Width of text string.
$x=$width-$text_width; // X - Postion of text string to allign Right.
///// Create the image ////////
$im = @ImageCreate ($width,$height)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 204, 204, 204); // Assign background color
$text_color = ImageColorAllocate ($im, 51, 51, 255); // text color is given
ImageString($im,5,$x,10,$text,$text_color); // Random string from session added
ImageJpeg ($im); // image displayed
imagedestroy($im); // Memory allocation for the image is removed.
?>
<?Php
header ("Content-type: image/jpg");
$height=40; // Canvas Height
$width=100; // Canvas Width
$font_height=imagefontheight(5);
$font_width=imagefontwidth(5);
$text="PLUS2NET"; // Text to be written on Image.
$no_text=strlen($text); // Number of chars in our text string.
$text_width=$no_text * $font_width; // Width of text string.
$x=$width-$text_width; // X - Postion of text string to allign Right.
$y=$height-$font_height; // Y- Postion of text string to allign bottom.
///// Create the image ////////
$im = @ImageCreate ($width,$height)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 204, 204, 204); // Assign background color
$text_color = ImageColorAllocate ($im, 51, 51, 255); // text color is given
ImageString($im,5,$x,$y,$text,$text_color); // Random string from session added
ImageJpeg ($im); // image displayed
imagedestroy($im); // Memory allocation for the image is removed.
?>
<?Php
header ("Content-type: image/jpg");
///// Create the image ////////
$font_height=imagefontheight(5);
$font_width=imagefontwidth(5);
$text='PLUS2NET.COM'; // Text string can be changed to reflect width of canvas to change.
$width = (strlen($text)*$font_width)+10 ; // Canvas width = String with, added with some margin
$height=$font_height + 10; // Canvas height = String height, added with some margin
$im = @ImageCreate ($width,$height)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 204, 204, 204); // Assign background color
$text_color = ImageColorAllocate ($im, 51, 51, 255); // text color is given
ImageString($im,5,5,$height/3,$text,$text_color); // Random string from session added
ImageJpeg ($im); // image displayed
imagedestroy($im); // Memory allocation for the image is removed.
?>
GD functions in PHP for handling images & graphics
How to check GD support in PHP