开发者

PHP and the GD library

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 in开发者_高级运维to a single image. Is this possible?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜