Skip to content

Instantly share code, notes, and snippets.

@Kraymer
Last active January 21, 2018 08:46
Show Gist options
  • Select an option

  • Save Kraymer/d014b40303dbfa4dda423efe5dba7a01 to your computer and use it in GitHub Desktop.

Select an option

Save Kraymer/d014b40303dbfa4dda423efe5dba7a01 to your computer and use it in GitHub Desktop.
PIL generation of timestamped favicons
import os
from PIL import Image, ImageDraw, ImageFont
# Generates timestamped favicon images for every day of the year, store images in 12 folders (one per month).
FONT = ImageFont.truetype(os.path.abspath(os.path.join('static', 'fonts', 'Avenir Next Condensed.ttc')), 60)
for month in [str(x).zfill(2) for x in range(1, 13)]:
os.makedirs(month)
for day in [str(x).zfill(2) for x in range(1, 32)]:
img = Image.open('public/img/favicon.png')
canvas = ImageDraw.Draw(img)
canvas.text((65, 50), (str(day).zfill(2)), font=FONT, fill=(165, 85, 64))
canvas.text((65, 0), (str(month).zfill(2)), font=FONT, fill=(165, 85, 64))
img.save(os.path.join('%s/favicon_%s.png' % (month, day)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment