Skip to content

Instantly share code, notes, and snippets.

@erraticgenerator
Created November 1, 2020 00:50
Show Gist options
  • Save erraticgenerator/ab3dcaf4ab0eb7ba50378fe17bc1f97f to your computer and use it in GitHub Desktop.
Save erraticgenerator/ab3dcaf4ab0eb7ba50378fe17bc1f97f to your computer and use it in GitHub Desktop.
from IPython.display import clear_output
# display images
monitor = False
# font filtering
df = pd.read_csv('./google-fonts-annotaion.csv')
paths = filter_fonts_get_paths(df, root=ROOT, subsets=['latin'], variants=['bold'], category='serif')
# text setup
text = "G"
x = IMG_WIDTH/2
y = IMG_HEIGHT*3/4
text_size = 400
# create save directory
target_dir = f'./fonts-images/{text}'
!mkdir -p $target_dir
# drawing setup
canvas = Image.new('RGB', (IMG_WIDTH, IMG_HEIGHT), "black")
draw = ImageDraw.Draw(canvas)
for i, path in enumerate(paths):
font = ImageFont.truetype(path, text_size)
draw.rectangle((0,0,IMG_WIDTH,IMG_HEIGHT),fill='black')
draw.text((x, y), text, 'white', font, anchor='ms')
canvas.save(f'{target_dir}/{i:05}.png', "PNG")
if monitor:
clear_output(wait=True)
plt.imshow(canvas)
plt.show()
if i % 200 == 0:
print(f'exporting {i:05}th of {len(paths)}')
print('Exporting completed.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment