PHP GD Font Width Calculate Help

安稳与你 提交于 2020-01-25 09:16:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1809200/php-gd-font-width-calculate-help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!