yekis Posted December 11, 2007 Share Posted December 11, 2007 i am displaying an string on top an image...this is my original code ..the original code works...however, when i want to word wrap the string....the string still displays only one line of text...it doesn't go/break to the next line.... ORIGINAL CODE: //displays string imagettftext($im, 18, 0, 10, 90, $white, $font, $description); REVISED CODE with WORDWRAPPING (can't find the bug)..tnx //displays string and defines its position imagettftext($im, 18, 0, 10, 90, $white, $font, $description); $text = $imagettftext; //wraps string??? $newtext = $newtext = wordwrap($text, 20, "<br />\n"); echo $newtext; ## is this needed?? ------------------------------ tnx!!! ..hoping for your immediate reply Quote Link to comment https://forums.phpfreaks.com/topic/81114-solved-word-wrapping-an-image-string-imagettftext-bug/ Share on other sites More sharing options...
JacobYaYa Posted December 11, 2007 Share Posted December 11, 2007 You want to use wordwrap($text, 20, "<br />\n"); what you are currently doing is adding a new line (\n) in the source but this won't affect the browser display. EDIT: Code will look something like this //$text = the text you want outputted by imagettftext() $new_text = wordwrap($text, 20, "<br />\n"); imagettftext($im, 18, 0, 10, 90, $white, $font, $new_text); Quote Link to comment https://forums.phpfreaks.com/topic/81114-solved-word-wrapping-an-image-string-imagettftext-bug/#findComment-411661 Share on other sites More sharing options...
yekis Posted December 11, 2007 Author Share Posted December 11, 2007 this is now my revised code...but what happens no string is displayed once i type some text on the description field when i press the submit button.....what are the errors on my code? tnx a lot! i'm a newbie to php and i'm beginnign to love this site.. REVISED CODE -------------------- $text = $_GET['description']; $new_text = wordwrap($text, 20, "<br />\n"); imagettftext($im, 18, 0, 10, 90, $white, $font, $new_text); --------------------------- **should i still use the echo $new_text syntax?...coz i removed it from the code...tnx Quote Link to comment https://forums.phpfreaks.com/topic/81114-solved-word-wrapping-an-image-string-imagettftext-bug/#findComment-411683 Share on other sites More sharing options...
JacobYaYa Posted December 11, 2007 Share Posted December 11, 2007 Looking at the comments on this function reference at php.net it is pretty involved to get multi-line text working with imagettftext(). This is the easiest user posted solution function imagettfmultilinetext($image, $size, $angle, $x, $y, $color, $fontfile, $text, $spacing=1) { $lines=explode("\n",$text); for($i=0; $i< count($lines); $i++) { $newY=$y+($i * $size * $spacing); imagettftext($image, $size, $angle, $x, $newY, $color, $fontfile, $lines[$i], $spacing); } return null; } if(isset($_GET['description'])){ $text = $_GET['description']; $new_text = wordwrap($text, 20, '\n'); imagettfmultilinetext($im, 18, 0, 10, 90, $white, $font, $new_text); } I was wrong to suggest wordwrap($text, 20, "<br />\n") , I forgot this was overlaying a string on an image so HTML formatting doesn't matter. Quote Link to comment https://forums.phpfreaks.com/topic/81114-solved-word-wrapping-an-image-string-imagettftext-bug/#findComment-411703 Share on other sites More sharing options...
yekis Posted December 11, 2007 Author Share Posted December 11, 2007 got it!! my php file now works fine!! tnx!!! Quote Link to comment https://forums.phpfreaks.com/topic/81114-solved-word-wrapping-an-image-string-imagettftext-bug/#findComment-411708 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.