Jump to content

Formating text within image


ivoilic

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/259136-formating-text-within-image/
Share on other sites

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.