trying to achieve this, you can see what its currently doing here
just wondering if someone already got something like this but running well...? TIA.
here's the code in the image(.php) on the right side...
just wondering if someone already got something like this but running well...? TIA.
here's the code in the image(.php) on the right side...
Code:
<?
function myWordWrap($txt,$font,$size,$width)
{
/*
word-wrapper. gets bounding box sizes for each word in a string, then
strings words together up to desired width. calls strpos and
imagettfbbox only once per word - so very fast.
this version reconcatenates the words with a <br> character where
the line break should be.
*/
$txt.=" "; // guaranteed to find end of line
$spaces=array();
$wids=array();
$i=0;
while(true)
{
$j=strpos(substr($txt,$i)," ");
if(!($j===false))
{
$spaces[]=$j+$i;
$bbox=imagettfbbox($size,0,$font,substr($txt,$i,$j+1));
$left=($bbox[0]>$bbox[6])?$bbox[6]:$bbox[0];
$right=($bbox[2]>$bbox[4])?$bbox[2]:$bbox[4];
$wids[]=$right-$left;
$i=$j+$i+1;
}
else break;
}
$lastspace=-1;
$cum=0;
$t2="";
for($i=0;$i<count($spaces);$i++)
{
if((($cum>0)&&($cum+$wids[$i])>$width)) // time for a line break
{
$t2.="<br>";
$cum=0;
$i--;
}
else
{
// we'll always get at least one word (even if too wide) thanks to
// ($cum>0) test above
$t2.=substr($txt,$lastspace+1,$spaces[$i]-$lastspace);
$cum+=$wids[$i];
$lastspace=$spaces[$i];
}
}
return $t2;
} // end function myWordWrap()
// check for user input, if none...use default values
if ( empty($t) ) {
$t = 'Custom Font PHP-GD On-the-fly: Haettenschweiler 14px';
}
if ( empty($width) ) {
$width = 436;
}
if ( empty($height) ) {
$height = 24;
}
if ( empty($font_size) ) {
$font_size = 14;
}
$text = $t;
$img = imagecreate($width, $height);
$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
$grayF7F7F7 = imagecolorallocate($img,247,247,247);
$gray333333 = imagecolorallocate($img,51,51,51);
imagefill($img,0,0,$grayF7F7F7);
// set font
$font = array(1 => "trebuchet","myriadweb","haettenschweiler");
$font_path = 'fonts/'.$font[3].'.ttf';
$textnew = myWordWrap($text,$font_path,$font_size,$width);
// array imagettftext ( resource image, int size, int angle, int x, int y, int color, string fontfile, string text)
Imagettftext($img,$font_size,0,0,14,$gray333333,$font_path,$textnew);
if (function_exists("imagegif")) {
header("Content-type: image/gif");
imagegif($img);
} elseif (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
imagejpeg($img, "", 80);
} elseif (function_exists("imagepng")) {
header("Content-type: image/png");
imagepng($img);
} elseif (function_exists("imagewbmp")) {
header("Content-type: image/vnd.wap.wbmp");
imagewbmp($img);
} else {
die("No image support in this PHP server");
}
imagedestroy($img);
?>

Comment