Skip to content

Instantly share code, notes, and snippets.

@nikolay-govorov
Created May 5, 2021 04:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikolay-govorov/c22bf58707f8bb0a5ae27a5df52b4868 to your computer and use it in GitHub Desktop.
Save nikolay-govorov/c22bf58707f8bb0a5ae27a5df52b4868 to your computer and use it in GitHub Desktop.
Generate woff and woff2 fromt TTF
# 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