Well, here is one way to do it, assuming you have the GD library installed with TTF support.
Basically, you will have a script (image.php) that creates the image from an existing image (button.jpg), then samples button.jpg's color palette to get a color for the text you wish to overlay.
Create an image called button.jpg and make it 100X100 px. This will be the background of your button.
Then, image.php might look like this ...
<?php
// declare the content type
Header("Content-type: image/jpeg");
// open the button background
$source = ImageCreateFromJPEG("button.jpg");
// create the new image
$image = ImageCreate(100, 100);
// copy the background image to the new image
$copy = imagecopy($image, $source, 0,0,0,0,100,100);
// get the font color from the image's palette
$col = ImageColorAllocate($image, 155, 155, 155);
// write the text
$text = $_GET["text"];
ImageTTFText($image, 16, 0, 10, 40, $col, "/home/fonts/ARIAL.TTF", "$text");
// create the actual final image
Imagejpeg($image,'',100);
// clean up
ImageDestroy($source);
ImageDestroy($image);
?>
* don't put any white space in image.php above the header function, it will break.
Then, you would use an IMG tag where you wanted to display the image ...
<IMG SRC='image.php?text=whatever'>
This is just a crude example, but it should get you started. Read up on these functions to learn how to tweak the parameters for image size, colors, font specs and x,y pixel positioning of the text.