Last active
October 15, 2018 23:05
-
-
Save error454/6ab48a54c8322499e9cbc3a535b9c157 to your computer and use it in GitHub Desktop.
Write numbers to images for baby shower guessing game
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
#Plow through all images in the folder | |
#Write a tracking number in the top left corner | |
#Save a text file that shows the original filename and the | |
#tracking number. | |
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
import glob, os | |
import random | |
index = 1 | |
answers = {} | |
def get_font_size(width, height): | |
return (height) / 15 #font size 24 for image height 1400 | |
#Get all files and then shuffle them... alphabetic answers | |
#could be suspicious and predictable to astute guests | |
files = glob.glob("*.jpg") | |
random.shuffle(files) | |
for file in files: | |
answers[index] = file | |
img = Image.open(file) | |
draw = ImageDraw.Draw(img) | |
font_mult = get_font_size(img.width, img.height) | |
font = ImageFont.truetype("arial.ttf", font_mult) | |
draw.text((0, 0), "#" + str(index),(255,0,0),font=font) | |
img.save("output/" + str(index) + ".jpg") | |
index += 1 | |
# write out the answers, sorted by key | |
with open('answers.txt', 'w') as file: | |
keylist = answers.keys() | |
keylist.sort() | |
for k in keylist: | |
file.write(str(k) + ": " + answers[k] + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment