display text in image in php using GD library

2:53 AM

(1) Comments

i got recently a snap of code that display text as an image using GD library , coz i wanted some thing to make email displayed as image to prevent spam and such annoying things
and GD library allows you to manipulate image as you want including adding text
here the code snippet

<?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);?>


special thanks to phpro

eslam

,

1 Response to "display text in image in php using GD library"

eslam said :
November 10, 2010 at 3:14 AM
sorry there is a bug in the code you must fill the image with background before you wtire the text

put
imagefill($im,0,0,$background_color);
before
imagestirng and it will work :)

Post a Comment