Home Tutorial Php Phpgd PHP GD add text to image


Share on Google+Share on Google+
PHP GD add text to image
Posted on: November 3, 2009 at 12:00 AM
This example shows how to add text to image in php gd.

PHP GD Add Text to Image Example


header ("Content-type: image/jpeg");

$string = "This is my text";

$font = 4;

$width = imagefontwidth($font) * strlen($string) ;

$height = imagefontheight($font) ;

$im = imagecreatefromjpeg("index.jpg");

$x = imagesx($im) - $width ;

$y = imagesy($im) - $height;

$backgroundColor = imagecolorallocate ($im, 255, 255, 255);

$textColor = imagecolorallocate ($im, 0, 0,0);

imagestring ($im, $font, $x, $y, $string, $textColor);



After running the program you will get the following output


Related Tags for PHP GD add text to image:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 3, 2009

Recommend the tutorial

Advertisements Advertisements