I have woff2 files that I would like to convert to ttf using Python and the fonttools library. I have seen some methods on how to convert ttf fonts to woff2 but I can't use them to do the opposite.
Thanks in advance
I have woff2 files that I would like to convert to ttf using Python and the fonttools library. I have seen some methods on how to convert ttf fonts to woff2 but I can't use them to do the opposite.
Thanks in advance
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)
Here's a CLI friendly script I wrote https://github.com/basisvectors/woff2otf
python woff2otf.py (filename.woff or filename.woff2 or directory for batch conversion) [target file or dir name]
Here's the one-line command (on Windows):
python -c "from fontTools.ttLib import woff2; import brotli; woff2.decompress('path/to/your.woff2', 'path/to/output.ttf')"
Make sure you have installed brotli. Use forward slash (/) for the file path instead of backslash (\). The output can be either TTF or OTF.