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
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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.