This, http://php.net/wordwrap, may helps you.hello! nice tutorial!! i was just wondering if you know how to wrap the text into a nice paragraph if the string is too long to fit onto the image?
sorry to be a pain, but i'm a bit new to this GD stuff! do you know how i can implement the php word wrap into the GD code below?
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
echo $newtext;
?>
thanks in advance for any help/tips!<?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);
?>
ps if i use $newtext in the GD code, won't it ignore the <br>s and /n's and just show the code as text? or will it process them and move down to a new line?
kev![]()
Last edited by snailofsatan; 05-09-2007 at 05:15 AM. Reason: addition
I've no experience with PHP and GD, so it may be wrong.
In your code, from PHP.net, you have first a variable, $text, with some text. hen your wordwraps it, and get a new text into the variable $newtext. In the other code, from this tutorial, you also need some text. The text is used in imagettfbbox() and imagettftext(). They both use the variable, $text, with is the content of the GET, "text". Because of that, you simply have to wordwrap that variable, and then then text of it will be used in the following code.
Code:<?php header('Content-type: image/png'); // ------------------------------------------------------ // This is the changed line... $text = wordwrap($_GET['text'], 20, "<br />\n"); // ------------------------------------------------------ $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); ?>
thankyoui'll give it a whirl!!
![]()
oh no, almost! rather that making a new line where each <br> \n is.. it just shows that text.. (rather than processing it)
Very nice sidewinder, I'm impressed at the time you spent on that. Next up, you may want to dig into using PHP,GD, and Flash together. PHP can generate images using GD and then spice them up with the flash code PHP can create.
I've been looking into using flash with php, the only thing I've been able to come up with is outputting information using xml, and have a flash action script read the xml.
so.. let's try it... but looks very interesting.To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
nice tut, just need to try it out now![]()
Real nice tutorial, this site is a real discovery![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks