Reputation: 1799
Currenly, I'm using fonttools(https://github.com/fonttools/fonttools) to convert font file ttf
to woff2
by ttx
command with 2 steps
ttf
to ttx
ttx
to 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?
Upvotes: 6
Views: 8011
Reputation: 376
If you install fonttools with the right dependencies, you can also this from the command-line:
./fonttools ttLib Roboto-Regular.ttf --flavor woff2 Roboto-Regular.woff2
Upvotes: 1
Reputation: 171
pip install --user --upgrade fonttools[woff]
python3
>>> from fontTools.ttLib.woff2 import compress
>>> compress('filename.otf','filename.woff2')
Upvotes: 5
Reputation: 1053
There's Google's woff2 CLI, so you can do this in command line instead of manually writing some scripts.
Upvotes: 2
Reputation: 5690
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')
NOTE: you might need to install other fontTools
dependencies ('brotli', others) to allow saving with flavor=woff2
to work correctly.
Upvotes: 17