Last active
August 29, 2015 14:06
-
-
Save iambibhas/bd04b18eda1337ea8a46 to your computer and use it in GitHub Desktop.
I'm using this script to generate QR codes for all the PyCon India 2014 attendees' names and ticket id
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 csv | |
import qrcode | |
from PIL import Image, ImageFont, ImageDraw | |
attendees = [] | |
with open('completed_attendees.csv') as userlist: | |
userreader = csv.reader(userlist, delimiter=',') | |
for row in userreader: | |
attendees.append({ | |
'ticket': row[0], | |
'name': row[1] | |
}) | |
font = ImageFont.truetype('ubuntu.ttf', 30) | |
qr = qrcode.QRCode( | |
version=1, | |
error_correction=qrcode.constants.ERROR_CORRECT_L, | |
box_size=6, | |
border=0, | |
) | |
for at in attendees: | |
backimg = Image.open('back.png') | |
qr = qrcode.QRCode( | |
version=1, | |
error_correction=qrcode.constants.ERROR_CORRECT_L, | |
box_size=6, | |
border=0, | |
) | |
qr.add_data(','.join([at['name'], at['ticket']])) | |
qr.make(fit=True) | |
qrimg = qr.make_image() | |
qrimg = qrimg.resize((210, 210)) | |
backimg.paste(qrimg, (20, 20)) | |
draw = ImageDraw.Draw(backimg) | |
# Just to check the images for people with longest names | |
if len(at['name']) > 25: | |
print at | |
draw.text((250, 20), at['name'], font=font, fill=(0, 0, 0)) | |
draw.text((250, 60), 'Ticket ID: {}'.format(at['ticket']), font=font, fill=(0, 0, 0)) | |
draw.text((290, 200), '_____________________________', font=font, fill=(0, 0, 0)) | |
backimg.save('new/{}.png'.format(at['ticket'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment