Text to image conversion in php
A string from db have to be converted into image but it is not working.
If the string is not taken from the db and defined in the file itself text is getting converted into image properly
Can anyone help to sort it out
Attaching the code used for the same
Thanks in advance
<?php
//error_reporting(E_ALL);
include('connect.php');
$res = mysql_query("select * from imgtext")or die(mysql_error());
$arr = mysql_fetch_array($res);
$data = $arr['data'];
$textval = str_replace('\r\n',"<br>",$data);
$textcolor = '666666';
//$string = preg_replace( "/\r|\n/", "", $textval);
//echo $string;die;
// $font="fonts";
$font="DidactGothic-Regular";
$size = 9;
$padding= 1;
$bgcolor= "ffffff";
$transparent = 0;
$antialias = 0;
$fontfile = $font;
$box= imageftbbox( $size, 0, $fontfile, $textval, array());
$boxwidth= $box[4];
$boxheight= abs($box[3]) + abs($box[5]);
$width= $boxwidth + ($padding*2) + 1;
$height= $boxheight + ($padding) + 0;
$textx= $padding;
$texty= ($boxheight - abs($box[3])) + $padding;
// create the image
$png= imagecreate($width, $height);
$color = str_replace("#","",$bgcolor);
$red = hexdec(substr($bgcolor,0,2));
$green = hexdec(substr($bgcolor,2,2));
$blue = hexdec(substr($bgcolor,4,2));
$bg = imagecolorallocate($png, $red, $green, $blue);
$color = str_replace("#","",$textcolor);
$red = hexdec(substr($textcolor,0,2));
$green = hexdec(substr($textcolor,2,2));
$blue = hexdec(substr($textcolor,4,2));
$tx = imagecolorallocate($png, $red, $green, $blue);
//print_r(imagettftext( $png, $size, 0, $textx, $texty, $tx, $fontfile, $textval ));
//die;
imagettftext( $png, $size, 0, $textx, $texty, $tx, $fontfile, $textval );
header("content-type: image/jpeg");
imagejpeg($png);
imagedestroy($png);
exit;
?>
check.php