PHP GD字体宽度计算帮助 [英] PHP GD Font Width Calculate Help

查看:173
本文介绍了PHP GD字体宽度计算帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的背景故事。我正在重新设计我的一个旧网站,并希望使用 Myriad Pro 为页面上的标题。这将是动态的PHP等。



起初,我想我应该使用CSS样式和定义Myriad作为主要字体。但使用typetester.org后,我发现Myriad,让我们说 Arial 有不同的高度,即使他们是相同的字体大小。



所以我可以使用CSS和风险打破我的设计在浏览器没有字体...



所以我想我可以使用 sIFR 。 (无论它叫做LOL)



最后我决定使用PHP GD。



问题:



最好设置一个固定的图像宽度,以容纳GD内的大量文本,或者根据字符数量动态计算图像宽度。 / p>

如果第二个更好,我如何计算像Myriad这样的非固定宽度字体的宽度?



PS,我不知道我的服务器是否支持 ImageMagick ,所以只有GD解决方案。 / p>

PPS,我可以使用不使用GD的Myriad Pro吗?

解决方案

功能



我一直在使用cufón用于文本替换,而不是 sIFR ,因为它使用JavaScript而不是Flash,它工作得很好。您需要从TTF生成JS字体。


OK a little background story. I am redesigning one of my old websites and I want to use Myriad Pro for the title on the page. This will be dynamic with PHP, etc.

At first I thought I should just use CSS styles and define Myriad as the main font. But after using typetester.org, I found that Myriad and let's say Arial are different heights even if they are the same font size.

So I could use CSS and risk breaking my design in browsers without the font...

So then I thought I could use sIFR. (Whatever it's called LOL)

At last I decided to use PHP GD.

Which brings me to my question:

Is it better to set a fixed image width large enough to accommodate lots of text within GD or to dynamically calculate the images width according to the amount of characters.

If the second one is better, how would I calculate the width of a non fixed width font like Myriad?

PS, I don't know if my server supports ImageMagick so GD solutions only please.

PPS, What is another way I can use Myriad Pro that doesn't resort to GD?

解决方案

There's a function for that.

I've been using cufón for text replacing instead of sIFR because it uses JavaScript instead of Flash and it worked beautifully. You need to generate a JS font from the TTF.

这篇关于PHP GD字体宽度计算帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆