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

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.

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 ?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.