- <?
- // GD Image Generator, based on Ro's work.
- // v0.1 Takes a name and places it on a predefined image
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Image Generator</title>
- </head>
- <body>
- <?
- // Full path to the font, preferably not relative
- $font = 'font.ttf';
- $fontSize = 18;
- $angle = 21.9;
- // If no name was posted, then show the form to request input
- echo "<form action="index.php" method="post">Enter your name: <input type="text" name="text" /><input type="submit" value="Generate Image" /></form>";
- // A name was posted so we can generate an image for the user
- // basing it on the source image
- $im = imagecreatefromjpeg('src.jpg');
- $s = imagettfbbox($fontSize, $angle, $font, $_REQUEST['text']);
- // Work out the math angle for the name on the banner image
- $c = imagecolorallocatealpha($im, $colour[0], $colour[1], $colour[2], $colour[3]);
- $x = $centrePoint[0] - ($width / 2) + $s[0];
- $y = $centrePoint[1] + ($height / 2) + $s[1];
- // Add the text to the image, at the correct angle, and in
- // the correct colour and font
- imagettftext($im, $fontSize, $angle, $x, $y, $c, $font, $_REQUEST['text']);
- // Send the image out to the browser
- imagejpeg($im, 'dest.jpg');
- }
- ?>
- </body>
- </html>
Code / PHP Snippets / GD: Name on Image
Download as Text : January 6th, 2009
This work is licensed under a