PHP:如何阅读“标题” .ttf 文件中的字体?
我确实需要能够从 .ttf true type 字体文件中提取元数据。
我正在建立一个中央数据库,其中包含我们所有设计师使用的所有字体(他们永远通过电子邮件交换字体以接管设计元素等)。我想获取所有字体,有些字体有愚蠢的名称,如 00001.ttf,所以文件名没有帮助,但我知道字体有元数据,我需要某种方法在 PHP 中提取它。
然后我可以创建一个循环来查看我指定的目录,获取此数据(以及我可以同时获取的任何其他数据),并将其添加到数据库中。
我真的需要帮助来读取此元数据部分。
I really need to be able to extract the metadata from a .ttf true type font file.
I'm building a central database of all the fonts all our designers use (they're forever swapping fonts via email to take over design elements, etc). I want to get all the fonts, some have silly names like 00001.ttf, so file name is no help, but I know the fonts have metadata, I need some way to extract that in PHP.
Then I can create a loop to look through the directories I've specified, get this data (and any other data I can get at the same time, and add it to a database.
I just really need help with the reading of this metadata part.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了此链接。它会做你想做的事(我已经测试过并发布结果)。只需将要从中解析数据的 TTF 文件的路径传递给类即可。然后使用
$fontinfo[1]。' '.$fontinfo[2]
为名称。如果您不想注册,这里是类
结果数据
使用
ttfInfo.class.php
2021 更新
这里是更新版本类的一些修复
https://github.com/Husamaamer/TTFInfo.git
I came across this link. It will do what you want (I've tested it and posted results). Just pass the class the path of the TTF file you want to parse the data out of. then use
$fontinfo[1].' '.$fontinfo[2]
for the name.In case you don't want to register, here is the class
Resulting Data
Usage
ttfInfo.class.php
Update 2021
Here is an updated version of the class with some fixes
https://github.com/HusamAamer/TTFInfo.git
与之前发布的答案非常相似...我已经使用这个类很长时间了。
Very similar to the previously posted answer... I've been using this class for a long time now.
既然 DOMPDF 项目的优秀人员已经为您完成了工作,为什么还要重新发明轮子呢?看看 php-font-lib @ https://github.com/PhenX/php-font -lib。它具有您所要求的所有功能,并且还支持其他字体格式。查看演示 UI @ http://pxd.me/php-font-lib /www/font_explorer.html 了解您可以从此库中获取哪些类型的信息。
Why reinvent the wheel when the fine people at DOMPDF project has already done the work for you? Take a look at php-font-lib @ https://github.com/PhenX/php-font-lib. This has all the features that you have asked for and supports other font formats as well. Look at the demo UI @ http://pxd.me/php-font-lib/www/font_explorer.html to get an idea about what kind of information you can get from this library.