Page 1 of 1

wrap text using gd

Posted: Wed May 09, 2007 12:22 pm
by SidewinderX
So I have this code:

Code: Select all

<?php
header('Content-type: image/png');
$text = $_GET['text'];

$im = imagecreatefrompng ("userbar.png");

$color = imagecolorallocate($im, 0, 0, 0);

$font = 'font.ttf';
$fontsize = 6;
$size = imagettfbbox($fontsize, 0, $font, $text); //calculate the pixel of the string
$dx = (imagesx($im)) - (abs($size[2]-$size[0])) - 20; //calculate the location to start the text
imagettftext($im, $fontsize, 0, $dx, 13, $color, $font, $text);
imagepng($im);
imagedestroy($im);
?>
Which displays the $_GET['text'] on an image dynamically. My question is, if $_GET['text'] is greater than 20 characters, how can I make the text print on the next line? I tried this:

Code: Select all

$text = wordwrap($_GET['text'], 20, "<br />\n");
But that didn't work. It printed the <br />\n rather than doing that it is suppose to. Any help is appreciated.

Thanks.

Posted: Mon May 14, 2007 9:52 am
by feyd
<br/> is for HTML. You just need \n.