Created
January 2, 2017 16:02
-
-
Save ddahan/f732710fb77ecf7934f00bc3925e1ee1 to your computer and use it in GitHub Desktop.
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
for cpt, elt_id in enumerate(input_ids): | |
# Copy the background to the new image, then draw it | |
new_bg = copy(bg_image) | |
draw = ImageDraw.Draw(new_bg) | |
# Generate a QR code as image | |
qr_image = data_to_qrcode(elt_id) | |
qr_x, qr_y = qr_image.size # Get width/height of QR code image | |
# Paste the QR code image to the background | |
# DELTA are used to change image placement (default is centered) | |
DELTA_X = 0 # Keep the QR code horizontally centered | |
DELTA_Y = 107 # Place the QR code according to the background | |
new_bg.paste(qr_image, | |
(bg_x//2 - qr_x//2 + DELTA_X, bg_y//2 - qr_y//2 + DELTA_Y)) | |
# (Optinnal) Draw the ID on the card, just above the QR code | |
draw.text((bg_x/2 - 240, 810), # No rule here, just try and adapt | |
text=elt_id, | |
font=fnt, | |
fill=0) | |
# Save the picture | |
full_path = os.path.join(output_path, elt_id + '.' + OUTPUT_FORMAT) | |
new_bg.save(full_path, OUTPUT_FORMAT) | |
# Delete in-memory objects (they're not necessary anymore) | |
del new_bg | |
del qr_image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment