fonttools将ttf转换为woff2 [英] fonttools convert ttf to woff2

查看:93
本文介绍了fonttools将ttf转换为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 to ttx
  • then convert ttx to woff2

但是它太慢了并且 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屋!

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