首页 > 解决方案 > 如何在 Python 中使用 fonttools 将 woff2 字体转换为 ttf?

问题描述

我有 woff2 文件,我想使用 Python 和 fonttools 库将其转换为 ttf。我已经看到了一些关于如何将 ttf 字体转换为 woff2 的方法,但我不能用它们来做相反的事情。

提前致谢

标签: pythonfontstruetypewoff2

解决方案


from fontTools.ttLib import woff2
# you also need brotli
import os

def convert(infilename, outfilename):
    with open(infilename , mode='rb') as infile:
        with open(outfilename, mode='wb') as outfile:
            woff2.decompress(infile, outfile)

这是我编写的 CLI 友好脚本 https://github.com/basisvectors/woff2otf

python woff2otf.py (filename.woff or filename.woff2 or directory for batch conversion) [target file or dir name]

推荐阅读