display text in image in php using GD library
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
special thanks to phpro
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 ($im, 255, 255, 255);
//black text
$text_color = imagecolorallocate ($im, 0, 0, 0);
// put it all together
imagestring ($im, $font, 0, 0, $string, $text_color);
// and display
imagejpeg ($im);?>
special thanks to phpro
1 Response to "display text in image in php using GD library"
put
imagefill($im,0,0,$background_color);
before
imagestirng and it will work :)
Post a Comment