Dynamically create an image from any text in PHP
Jun 29, 2009 Useful PHP
My goal when I did this quick script was to use php to convert text into images, so that email addresses could be dynamically inserted into pages, making spam harvesters’ life a little harder.
Of course it has many more uses, one of them being to avoid web spiders from fetching a specific word or two -say a promo code you don’t want to be indexed.
To run this script you must have GD library installed. We’ll take parameters via GET and put that text into the image:
<?php if(!isset($_GET['text'])) { die("No text provided"); } header ("Content-type: image/png"); $textToConvert = $_GET['text']; $font = 4; $width = ImageFontWidth($font) * strlen($textToConvert); $height = ImageFontHeight($font); $im = @imagecreate ($width,$height); $background_color = imagecolorallocate ($im, 255, 255, 255); //this means it's white bg $text_color = imagecolorallocate ($im, 0, 0,0);//and of course black text imagestring ($im, $font, 0, 0, $textToConvert, $text_color); imagepng ($im); ?>
Save this as texttoimage.php and then when you want to create the image, link to it in an ‘img’ tag.
<img src="texttoimage.php?text=emailAddress@emailProvider.com">
Hey, be warned, the above won’t stop spammers and spiders from fetching your email address! They’ll see and properly parse the query string -this is for demonstration purposes only.
Tags: php convert text into image, php email to image, php merge text into image, php write text to an image, php write to image, Write text and convert into image


July 2nd, 2009 at 2:59 am
Neat!
November 12th, 2009 at 6:35 pm
wow, didn’t think it could be this simple! You ROCK!!!!
November 17th, 2009 at 4:02 am
great work.. if i provide text value automatically then how can i call this image..
January 13th, 2010 at 6:25 am
great man