In this tutorial I will be teaching you to make a really basic text on plain/no background system. I'll be using the GD library so check you have that installed ;).
Simple enough idea, you can allow users to edit the text appearing on the image with GET details. The idea is that you can adapt this simple script into your own site. It's been coded for Bozebo so he can use it to put emails in profiles into images and stop bots from grabbing. It can be adapted to take data from a database and display it, you could even make an image verification system with it!
I'm not going to go through it line by line, instead I'll just annotate it as I go. Enjoy...
PLAIN TEXT
PHP:
- <?
- header("Content-type: image/png"); // Tell the browser it's an image, not a .php file.
- $text = stripslashes($_GET['text']); // Take the text and stop it from messing up with '
- $number = strlen($text); // Count the chars in the text.
- $number = ($number*7)+9; // Times this by 7 and add 9 to make it look the right size.
- $im = imagecreate($number, 24); // Create the basic size, $number x 24
- $colour1 = imagecolorallocate($im, 0, 0, 0); // Background (RGB) black.
- $colour2 = imagecolorallocate($im, 255, 255, 255); // Background white.
- imagestring($im, 3, 5, 5, $text, $colour2); // Add the text to the image.
- imagepng($im); // Create and display the image.
- imagedestroy($im); // Cast the image from the server (will cause lag eventually if you don't).
- ?>
discuss this topic to forum
