Extract Font Glyphs

2019-06-11 15:30发布

问题:

I have this problem across my mind, any help will be appreciated. Is there are PHP function, or library that can extract some glyphs form a font file?

Edit: By means to extract some glyphs, I wanted to create a new font file based on the glyphs extracted (so it has smaller bytes), or just get the glyphs and create base64 encoded font data from it so I can embed it via @font-face. I just wanted to get rid glyphs that has no use so CSS (base64) or font file will be loaded faster.

回答1:

I can understand your question two ways. Either you want to pull the image out of the font file directly, or you want to print with that font as text in an image.

But both have the same answer:

Try GD or ImageMagick to pull the image of a glyph from a font file using the font to print that character into the image. Don't open the font like an image, use the font as it was intended. You can then print the glyph at whatever size you want and use it however you want.



回答2:

You are trying to make a subset font aren't you? This problem have been investigated heavily by the embedded font community.

Even that, there is not definite answer here. Last time I checked people write Perl/C programs to extract binary data from font files, based on TTF/OTF spec.

If you are using Latin font, don't brother coz it's small enough. If you are using CJK font like me, FontForge could help you copy and paste the gryphs by hand. Other than that you need to write a script/program by yourself.



标签: php fonts glyph