2

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

提前致谢

4

3 回答 3

1
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]
于 2022-01-09T17:53:42.137 回答
1

我想它可以用来fontTools.ttLib.woff2.decompress()实现这一目标

于 2020-07-03T08:35:48.833 回答
0

这是单行命令(在 Windows 上):

python -c "from fontTools.ttLib import woff2; import brotli; woff2.decompress('path/to/your.woff2', 'path/to/output.ttf')"

确保你已经安装了 brotli。使用正斜杠 ( /) 代替反斜杠 ( \) 作为文件路径。输出可以是 TTF 或 OTF。

于 2022-02-09T02:55:36.300 回答