Monday, February 21, 2011

Change text to image in php script

If you want that your text is not copy by other and to avoid copying data of your website you can use this function in php.It will change the text into the image of png format.

header ("Content-type: image/png");
$string = $_GET['txt'];                                           
$font   = 4;
$width  = ImageFontWidth($font) * strlen($string);
$height = ImageFontHeight($font);

$im = @imagecreate ($width,$height);
$background_color = imagecolorallocate ($im, 255, 255, 255); //white background
$text_color = imagecolorallocate ($im, 0, 0,0);//black text
imagestring ($im, $font, 0, 0,  $string, $text_color);
imagepng ($im);

No comments:

Post a Comment