wrap text using gd

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

wrap text using gd

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

<br/> is for HTML. You just need \n.
Post Reply