This can be done in PHP just with your browsers help.
If you output the header values as
Header("Content-type: image/jpeg");
Then you can output an image straight out of a script straight to the browser. The browser recognises the file type as an image and displays it accordingly. You can also use a standard html img tag to output the image.
You will however have to have the gd image functions compliled into php
Then you can do things like
<?php
header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>