I think I remember making one of these a while back... But mine actually created a new file for each newly generated image to lessen the stress on the server.
Anyways, here's my 15 minutes at it assuming the file name is sig.php:
CODE
<?php
$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$sports = $_REQUEST['sports'];
// check to see if someone's hit generate already
if( isset($name) == true && isset($age) == true && isset($sports) == true ) {
Header('Content-type: image/png');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');
// create image w/ dimensions
$img_width = 200;
$img_height = 100;
$image = imagecreate($img_width, $img_height);
// set bg colour
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $img_width, $img_height, $white);
// border
imagefilledrectangle($image, 0, 0, $img_width, 0, $black);
imagefilledrectangle($image, 0, $img_height-1, $img_width, $img_height-1, $black);
imagefilledrectangle($image, 0, 0, 0, $img_height, $black);
imagefilledrectangle($image, $img_width-1, 0, $img_width-1, $img_height, $black);
// text
ImageTTFText($image, 8, 0, 10, 17, $black, '/path/to/font/file.ttf',
"Name: " . $name . "\nAge: " . $age . "\nSports: " . $sports);
// output and destroy
imagepng($image);
imagedestroy($image);
}
// if not, go ahead and show the form
else {
print ("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">
<head>
<title>Dynamic Signature Generator</title>
<meta http-equiv=\"Content-type\" content=\"text/html; charset=ISO-8859-1\" />
<style type=\"text/css\">
body { font-family: tahoma, verdana, arial; }
img { verical-align: middle; border-style: none; }
</style>
</head>
<body>
<h1>Dynamic Signature Generator</h1>
<form method=\"post\" name=\"sig\" action=\"sig.php\">
<small>
Name: <input type=\"text\" name=\"name\" value=\"\" /><br />
Age: <input type=\"text\" name=\"age\" value=\"\" /><br />
Sports: <input type=\"text\" name=\"sports\" value=\"\" /><br />
<input type=\"submit\" value=\"Generate\" />
</small>
</form>
</body>
</html>");
}
?>
WARNING: this is a
VERY BASIC and slightly
INSECURE method of doing it (because I'm not running any checks on what the user is inputting), but it gets the job done. This code should at least give you some insight as to what to expect.
Here is the form:
Click to view attachmentAnd the output of the form:
Click to view attachmentHope this helps.
Cheers,