convert text into an image using php

by Guna 2012-07-23 14:58:22

Below code will lets you convert given text into an image using php. This function takes text as an
input and converts it as image finally returns as image tag.


function txt2img($txt){
ob_start();
$ori_str=$txt;
$font = 4;
$width = ImageFontWidth($font) * strlen($txt);
$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, $txt, $text_color);
echo imagepng ($im);
$rawImageBytes = ob_get_clean();
$imgtag="";
return $imgtag;

}

echo txt2img('guna');

Tagged in:

851
like
0
dislike
0
mail
flag

You must LOGIN to add comments