Created
May 5, 2021 04:26
-
-
Save mrdimidium/c22bf58707f8bb0a5ae27a5df52b4868 to your computer and use it in GitHub Desktop.
Generate woff and woff2 fromt TTF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install brotli fonttools | |
from os import listdir | |
from os.path import isfile, join | |
from fontTools.ttLib import TTFont | |
path_fonts = './static/fonts/alegreya-sans' | |
path_ttf = f'{path_fonts}/ttf' | |
path_woff = f'{path_fonts}/woff' | |
path_woff2 = f'{path_fonts}/woff2' | |
ttf = [f for f in listdir(path_ttf) if isfile(join(path_ttf, f))] | |
for font in ttf: | |
f = TTFont(join(path_ttf, font)) | |
f.flavor = 'woff' | |
f.save(join(path_woff, font.replace('.ttf', '.woff'))) | |
f.flavor = 'woff2' | |
f.save(join(path_woff2, font.replace('.ttf', '.woff2'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment