954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Split text line into two or three text lines and put on IMG using GD

Hello everybody,

i need help from you guys.. I want to split text line into 2-3 lines and put it on image using GD. I know how to write text on image with GD, but i don't know how to split text to get the last line..

Here is what it should look like:


If text line exceeds limited width as example 200px then it should split text into two lines and if the second line also exceeds limited width then it should split second line too making 3 text lines of 1.
I can't use wordwrap, because then i cant center last line.. As example there is a text line: "Are you posting in the most appropriate place to receive relevant replies? This is the PHP Forum."

And if i try to use wordwrap then ir looks like this:
"Are you posting in the most
appropriate place to receive
relevant replies? This is the
PHP Forum."

So i cant center last line.. Splited text should look like:
"Are you posting in the most
appropriate place to receive
relevant replies? This is the
PHP Forum."

I know how to center text on image, but HOW i can get the last line to center it? If somehow i could get it then i would use variable like $firstline and $secondline in imagettftext

imagettftext($image_2,$font_size6,0,$x-10,$image_height-100,$black,$font3,$firstline);
imagettftext($image_2,$font_size4,0,$x2+3,$image_height-55,$black,$font4,$secondline);

Thank you in advance! :)

zevo
Newbie Poster
2 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This page shows how to determine the width of a given text. You can use it to determine where to split your text, and use that width to center if needed.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
This page shows how to determine the width of a given text. You can use it to determine where to split your text, and use that width to center if needed.

Yea, but how to split at example 300px width? Which function can do that? And how to take first line to $firstline and splited second line to $secondline ?

zevo
Newbie Poster
2 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

There is no function that does that for you, you'll have to write your own.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: