Asperon Posted August 27, 2007 Share Posted August 27, 2007 Is it possible to take text from a POST that is being written to an image using the GD ImageTTFText function and breaking it apart so that it writes like a paragraph. For example if you have "Welcome to the happiest place on earth" typed into the input text box and subinted but the width of the image it is being written too only is wide enough to hold "Welcome to the happiest", is there a function that automatically breaks text in the image to a second line?? or do I have write my own function for that? Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/ Share on other sites More sharing options...
Asperon Posted August 27, 2007 Author Share Posted August 27, 2007 I guess no response means I need to program it to do that myself.. Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335619 Share on other sites More sharing options...
Jessica Posted August 27, 2007 Share Posted August 27, 2007 You would need to add a new line \n after X characters. Yes, you'll have to do some yourself Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335624 Share on other sites More sharing options...
Barand Posted August 27, 2007 Share Posted August 27, 2007 like this <?php $text = "Welcome to the happiest place on earth"; $textArray = explode('|', wordwrap($text,25,'|')); $y = $firstLinePos; foreach ($textArray as $txt) { imagettftext(..... $txt); $y += $lineHeight; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335652 Share on other sites More sharing options...
Asperon Posted August 27, 2007 Author Share Posted August 27, 2007 thank you, though, it seems that I have another problem now, but I"m not sure why. I have some math in my code that aligns my text where I want it, centers it and then indents. The more characters the text is, with the explode and wordwrap, the farther to the right the text shifts. <?php //$ln1[0] = text //$ln1[2] = font size $box = ImageTTFBBox($ln1[2],0,$font,$ln1[0]); $d = $box[2] - $box[0]; $align = $width/2 + 30 - $d/2; $textArray = explode('|', wordwrap($ln1[0],25,'|')); $y = 40; foreach ($textArray as $txt) { ImageTTFText($im,$ln1[2],0,$align,$y,$color,$font,$txt); $y += $ln1[2] + 3; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335663 Share on other sites More sharing options...
Barand Posted August 27, 2007 Share Posted August 27, 2007 You need to calculate width and position each time thru the loop, for each line of text Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335676 Share on other sites More sharing options...
Asperon Posted August 27, 2007 Author Share Posted August 27, 2007 well I tried just sticking my calculations in the loop, but it gave me the same results, so guess I have to tweek them? Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335682 Share on other sites More sharing options...
Asperon Posted August 27, 2007 Author Share Posted August 27, 2007 lol I left the first set up so it still used that...it works more properly now, but its is staying aligned to the left, instead of center, thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335684 Share on other sites More sharing options...
Asperon Posted August 27, 2007 Author Share Posted August 27, 2007 k, I got it, heres the reslult...thank you all for your help I really appreciate it <?php $textArray = explode('|', wordwrap($ln1[0],25,'|')); $y = 40; foreach ($textArray as $txt) { $box = ImageTTFBBox($ln1[2],0,$font,$txt); $d = $box[2] - $box[0]; $align = $width/2 + 30 - $d/2; ImageTTFText($im,$ln1[2],0,$align,$y,$color,$font,$txt); $y += $ln1[2] + 3; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66929-solved-imagettftext-paragraph-issue/#findComment-335686 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.