0

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! :)

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by pritaeas
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.

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.

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 ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.