28-09-2011

PHP Text to image

This simple code example will open an image file and put the text specified in the GET parameter to via GD

header("Content-type: image/png");
$string = $_GET['txt'];
$im = imagecreatefrompng("somepngimage.png");
$color = imagecolorallocate($im, 255, 255, 255);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
$py = 9;
$fontSize = 1;
 
imagestring($im, fontSize, $px, $py, $string, $color);
imagepng($im);
imagedestroy($im);

Comments:

Your comment:

»

 

[x]