
Originally Posted by
purpleflame
So I found this other function to place text called imagettftext. However, its makes the same problem. I liked this function since it lets me use a normal font like arial. However, it seems that FreeType library needs to be available to use it. Is that causing the problem?
Not really, you just need the .TTF file for the font that you wish to use on the server.
PHP Code:
<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
// Print the text, using the predefined font file
imagettftext($image, 20, 0, 10, 20, $col_red, $font, 'Working');
?>
As for the wrapped text, a quick Google search yielded the following. I've not tested it, but it looks ok. You could change it slightly to use imagettftext instead of imagestring.
Also, I would do some major editing on it so that it doesn't give the image, it just adds the text... Maybe I'll do that tomorrow 
PHP Code:
<?php
function make_wrapped_txt($txt, $color = 000000, $space = 4, $font = 4, $w = 300)
{
if (strlen($color) != 6)
$color = 000000;
$int = hexdec($color);
$h = imagefontheight($font);
$fw = imagefontwidth($font);
$txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
$lines = count($txt);
$im = imagecreate($w, (($h * $lines) + ($lines * $space)));
$bg = imagecolorallocate($im, 255, 255, 255);
$color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8),
0xFF & $int);
$y = 0;
foreach ($txt as $text)
{
$x = (($w - ($fw * strlen($text))) / 2);
imagestring($im, $font, $x, $y, $text, $color);
$y += ($h + $space);
}
header('Content-type: image/jpeg');
die(imagejpeg($im));
}
?>