Convert a text to image

by Guna 2014-03-07 18:25:33

Sometimes we need to display texts as image to avoid data harvest, this php script will help to achieve that. Save this below code as php file in your htdocs.

Run this page by passing a text, similar to this one:
http://localhost/convert.php?txt=example


if(!isset($_GET['txt']))
{
exit();
}

header ("Content-type: image/png");
$string = $_GET['txt'];
$font = 3;
$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);

Tagged in:

592
like
0
dislike
0
mail
flag

You must LOGIN to add comments