fonttools将ttf转换为woff2 [英] fonttools convert ttf to woff2
问题描述
目前,我正在使用fonttools( https://github.com/fonttools/fonttools ),可通过 ttx
命令以2个步骤将字体文件 ttf
转换为 woff2
Currenly, I'm using fonttools(https://github.com/fonttools/fonttools) to convert font file ttf
to woff2
by ttx
command with 2 steps
- 将
ttf
转换为ttx
- 然后将
ttx
转换为woff2
- convert
ttf
tottx
- then convert
ttx
towoff2
但是它太慢了并且 ttx
文件很大,有什么方法可以通过使用fonttools直接将 ttf
转换为 woff2
来提高性能?
But it's too slow and ttx
file to big, is there any way to convert ttf
to woff2
directly by using fonttools to improve performance?
推荐答案
在Python中安装了fonttools(virtualenv,pipenv等)
With fonttools installed in your Python (virtualenv, pipenv, etc):
$ python
>>> from fontTools.ttLib import TTFont
>>> f = TTFont('path/to/your/file.otf')
>>> f.flavor='woff2'
>>> f.save('path/to/your/file.woff2')
注意:您可能需要安装其他 fontTools
依赖项('brotli',其他),以允许使用 flavor = woff2
进行保存才能正常工作.
NOTE: you might need to install other fontTools
dependencies ('brotli', others) to allow saving with flavor=woff2
to work correctly.
这篇关于fonttools将ttf转换为woff2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!