Drawing a string as an image is a handy way to disguise an eMail address so spam sniffers can't get it as easily. The only catch to creating a dynamic image with your eMail in it is the eMail to be displayed must be passed via the query string to enable static HTML to use it. So, the eMail must be encrypted slightly in order to not defeat the purpose of not typing your eMail address outright. I wrote the following script to do so:
Save the following as email.php
<?php
if ($_GET['addr'] != "") {
$msg = $_GET['addr'];
$msg = preg_replace("/\[dot]/",".",$msg);
$msg = preg_replace("/\[at]/","@",$msg);
$final = "";
for ($i=0; $i<=strlen($msg); $i++) {
$final .= substr($msg, strlen($msg)-$i, 1);
}
$msg = $final;
$char_width = 8;
$char_height = 17;
$padding = 3;
$width = $padding*2+strlen($msg)*$char_width;
$height = +$padding*2+$char_height;
$im = imagecreatetruecolor($width,$height);
imagealphablending($im, FALSE);
imagesavealpha($im, TRUE);
$bg = imagecolorallocatealpha($im, 255, 255, 0, 100);
$text = imagecolorallocatealpha($im, 0, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, $width, $height, $bg); imagestring($im, 4, $padding, $padding, $msg, $text);
} else {
$im = imagecreatetruecolor(1,1);
imagealphablending($im, FALSE);
imagesavealpha($im, TRUE);
$bg = imagecolorallocatealpha($im, 255, 0, 0, 125);
imagefilledrectangle ($im, 0, 0, 1, 1, $bg); }
header('Content-type: image/jpg');
imagepng($im);
imagedestroy($im);
?>
If the script is called without an eMail address, it outputs a 2x2 transparent image.
To call the script to generate the eMail "user@home.com", the HTML tag would be:
<img src="email.php?addr=moc[dot]emoh[at]resu">
To 'encrypt' the eMail address to pass to the script, write the address backwards and replace "." with "[dot]" and "@" with "[at]". It's not the most ironclad protection, but it thwarts most casual eMail sniffers.