tags:

views:

39

answers:

2

I'm using GD to change the font on user posted comments. What I have so far works for a single post but what I need are all of the posts output into a single image. Is this possible?

A: 

Jim, you'd better stop using GD and look at the <font> tag in HTML docs. Or let server eat resources and users eat traffic.

If you really need to stick to GD for some reason, just give as some code. In particular, MySQL query till image output.

P.S. Everything is possible.

Andrejs Cainikovs
Don't use the <font> tag, use CSS.
siride
I didn't say to use it.
Andrejs Cainikovs
Thanks Andrejs. I don't have to use GD and I have noticed that it is WAY slow while compiling the posts. I'd love to have another alternative such as someone has suggested sIFR.
Jim
+3  A: 

Don't use GD. Instead, use CSS to control fonts. For instance, output your comment inside a div with a class:

<div class="comment"><?=$comment_text></div>

And then in your CSS:

div.comment { font-family: "Courier New"; }
div.comment * { font-family: inherit !important; }

What this will do is force the font inside your comment to Courier New, even if the comment contains HTML that uses the <font> tag or specifies font in a style attribute.

The first style rule says that all <div> elements with the class comment will use Courier New as its font. The second rule tells all descendants of that div (ie. any elements within the div) to inherit the font styling, and !important tells the browser that that rule should overrule any other font-family rule on the element.


Update based on your comment:

If you want to use a font that you think most users won't have, you can still solve this with CSS, by specifying an @font-face declaration and hosting the font file on your server.

Take a look at Bulletproof @font-face syntax for an example of how you can use @font-face in a cross-browser way. There's also a @font-face generator that you can use.

Daniel Vandersluis
Daniel, thanks for the snippet. Unless I'm missing something, this won't work because the TTF I am using is one that will not be on the users' system. Your thoughts?
Jim
@Daniel Vandersluis: Most fonts are proprietary, and unless you have the copyright holders consent, you can't distribute the font file.
jmz
@jmz I understand that, I'm making the assumption that @Jim is able to distribute the font. Anyways, the point of this is not legality but technique.
Daniel Vandersluis
Daniel, thanks for the font face trick. I didn't know that. For the debate here, this is a free, redistributable font so I should be just fine there. I tend to be more pragmatic on programming and if I have to implement something that is going to require a couple of hours of work to keep these comments in a strict CSS environment over using a font face tag, I will always choose the latter.
Jim