PHPRO.ORG

Many folks want to generate text to an image. The PHP GD lib allows us to do just this. Here we show a simple method to turn an email address into an image for use on a web page. Some say this helps to keep the email harvesters away, but with optical character recognition this is still possible.



<?php

  
// show the correct header for the image type
  
header("Content-type: image/jpg");

  
// an email address in a string
  
$string "email@example.com";

  
// some variables to set
  
$font  4;
  
$width  ImageFontWidth($font) * strlen($string);
  
$height ImageFontHeight($font);

  
// lets begin by creating an image
  
$im = @imagecreatetruecolor ($width,$height);

  
//white background
  
$background_color imagecolorallocate ($im255255255);

  
//black text
  
$text_color imagecolorallocate ($im000);

  
// put it all together
  
imagestring ($im$font00,  $string$text_color);

  
// and display
  
imagejpeg ($im);
?>