Oh yep, that's quite possible.
If you're interested in adding effects to the texts there's not a lot that the GD library can do except add makeshift shadows by duplicating the text and moving it appropriately as shown below. If you don't want the shadow then just get rid of that one line.
This code outputs an entire image (I adapted this from code that I used for a blog signature) so it'll do exactly what you want it to.
Code:
<?php
// The lines below prevent the file from being cached (i.e. it is reloaded upon each view) and are currently commented - should only be uncommented if you are outputting dynamic information which will be regularly updated, and also if you don't mind using a lot of bandwidth on your host. You can use MySQL or an RSS grabber etc to output stuff dynamically.
#header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
#header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
#header("Cache-Control: no-store, no-cache, must-revalidate");
#header("Cache-Control: post-check=0, pre-check=0", false);
#header("Cache-Control: max-age=0");
#header("Pragma: no-cache");
header("Content-type: image/x-png"); // can use 'Content-type: image/jpeg/gif/x-png' instead (change output at end also)
// Load image template
$im = imagecreatefrompng("background.png"); // location of the background image (should also be imagecreatefromjpeg/gif if the file type is not png)
$textcolour = imagecolorallocate($im, 255, 255, 255); // colour of the text you're adding in an RGB value
$textshadow = imagecolorallocate($im, 0, 0, 0); // colour of the shadow on your text (if any) in an RGB value
// The following function gives text center alignment
function centerText($size, $angle, $font, $text, $centerPt){
$bbox = imagettfbbox($size, $angle, $font, $text);
$width = $bbox[2] - $bbox[0];
$halfPt = $width / 2;
$newX = $centerPt - $halfPt;
return $newX;
}
// imagettftext ($im, font size, angle, location x-coord, location y-coord, font colour using imagecolorallocate() function, font file location, text);
// the centerText() function is a bit confusing to grasp but it goes in the x-coord parameter and you basically enter the same parameters into it as you did for the rest of the imagettftext() function. Read its parameters above to see what to enter.
// First apply a shadow (1px off the actual text), then actual text afterwards
$text = "This is the string of text you want to output";
imagettftext ($im, 20, 0, centerText(20, 0, './verdana.ttf', $text, 85) + 1, 87, $textshadow, "./verdana.ttf", $text);
imagettftext ($im, 20, 0, centerText(20, 0, './verdana.ttf', $text, 85), 86, $textcolour, "./verdana.ttf", $text);
// Throwing out the final image
imagepng($im);
// or
// imagepng($im);
// or
// imagejpeg($im,'',100);
// (change content-type in header also as necessary)
// Free the memory
imagedestroy($im);
?>