ivoilic Posted March 17, 2012 Share Posted March 17, 2012 So basically I have text which appears on an image. $ability = "$title gets ability"; //Create Ability imagettfbbox(30, 0, $font, $ability); imagettftext($image, 30, 0, 70, 700, $fontcolor, $font, stripslashes($ability)); But the line of text is longer than the width of the area on the image it needs to fit in. How can I change this so it automatically starts a new line once it reaches the end of said area? Quote Link to comment https://forums.phpfreaks.com/topic/259136-formating-text-within-image/ Share on other sites More sharing options...
Mahngiel Posted March 17, 2012 Share Posted March 17, 2012 PHP's GD function can't determine the length of your texts inherently. However, you can write conditional statements that will dynamically wrap the text (or shrink the font size) depending on your preference. Quote Link to comment https://forums.phpfreaks.com/topic/259136-formating-text-within-image/#findComment-1328512 Share on other sites More sharing options...
ivoilic Posted March 17, 2012 Author Share Posted March 17, 2012 Can you give me an example or link or something. I am some what of a noob. Quote Link to comment https://forums.phpfreaks.com/topic/259136-formating-text-within-image/#findComment-1328527 Share on other sites More sharing options...
litebearer Posted March 17, 2012 Share Posted March 17, 2012 This link will show you how to wrap text on an image http://php.net/manual/en/function.imagettftext.php Look at the example from John Conde (about the 4th one down). Keep in mind you will need to do some experimenting beforehand to determine what font-sizes and character lengths will work best with different size images. Perhaps set up a SWITCH statement that accounts for those issues. Quote Link to comment https://forums.phpfreaks.com/topic/259136-formating-text-within-image/#findComment-1328596 Share on other sites More sharing options...
ivoilic Posted March 18, 2012 Author Share Posted March 18, 2012 Found a bit of code that solved my problem: // get the quote and word wrap it $quote = wordwrap($quotes[$pos],20); Im unsure what the 20 is actually the value of. Also it seems if you put in one line of text without spaces this method fails to work! HELP! Quote Link to comment https://forums.phpfreaks.com/topic/259136-formating-text-within-image/#findComment-1328600 Share on other sites More sharing options...
Mahngiel Posted March 18, 2012 Share Posted March 18, 2012 Take a look at the wordwrap() docs to understand how to use the function. "20" in your case is how many characters (spaces included) to count before wrapping. Taking a look at example 2 should be sufficient to help you with your long word problems. Quote Link to comment https://forums.phpfreaks.com/topic/259136-formating-text-within-image/#findComment-1328667 Share on other sites More sharing options...
ivoilic Posted March 18, 2012 Author Share Posted March 18, 2012 Thank you Mahngiel! Problem Solved!!!! :D :D :D Quote Link to comment https://forums.phpfreaks.com/topic/259136-formating-text-within-image/#findComment-1328779 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.