IT.COM

{PHP} A quick GD question

Spaceship Spaceship
Watch

Alex.

Account Closed
Impact
5
Hi, I've seen some dynamic sigs, where there are multiple rows of text.
To do this, would I just use imagettftext multiple times, or is there a seperate function for this??

thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
You would use \n to make a new line.

For example:
PHP:
imagettftext(/* Preceding arguments */ "This is line 1\nLine 2\nLine 3");
 
0
•••
Thanks, how could i add formatting?

like
sig.gif


is this just \n ???

and what about if i wanted to add two different types of text, eg text a, slanted and red, and text b, horizontel and blue?

is this just different imagettftext?
 
Last edited:
0
•••
To do what you want, you'll need to manage the text positioning by hand -- \n won't help you.

A font's color is determined by a parameter you pass to imagettftext. You create the color via a call to imagecolorallocate.

Font weight and style (like bold and italic) are handled by the font itself. In other words, if you want Arial drawn in bold, you'll need to load a font called "Arial Bold". You can "fake" bold text to a degree by redrawing the same text 1 or 2 pixels down and to the right, but there's no programmatic way to synthesize italic text -- you'll need to have an actual italic version of the font which you can load.

To decide where to draw each line (or part of a line) of text, you need to do some math (the more fonts and weights and italics on a given line, the more math you'll need to do). The function imagettfbbox gives you the bounding rectangle for a given string of text in a given font.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back