Last active
August 29, 2015 14:10
-
-
Save bkeating/2f87575a4633236734df to your computer and use it in GitHub Desktop.
Generate a range of random 'codes' for Santa on the Square photo service
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 random | |
import string | |
import subprocess | |
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
codes = [] | |
for i in range(1, 251): | |
char_pool = string.ascii_uppercase + string.digits | |
# Generate a random code | |
r = ''.join([random.choice(char_pool) for n in xrange(5)]) | |
# Check generated code against pre-existing codes. | |
if r not in codes: | |
codes.append(r) | |
# Open template image and draw on it | |
img = Image.open("template.png") | |
draw = ImageDraw.Draw(img) | |
font = ImageFont.truetype("Inconsolata.otf", 72) | |
draw.text((430, 527), str(i), (0,0,0), font=font) | |
draw.text((430, 706), str(r), (0,0,0), font=font) | |
# save | |
img.save('./cards/%02d%s.png' % (i, r)) | |
print "Created card for #%s, Code: %s" % (i, r) | |
print "Merging all cards into a single PDF..." | |
subprocess.call('convert ./cards/* output.pdf', shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment