Last active
January 21, 2018 08:46
-
-
Save Kraymer/d014b40303dbfa4dda423efe5dba7a01 to your computer and use it in GitHub Desktop.
PIL generation of timestamped favicons
This file contains hidden or 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
| 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