Created
January 9, 2020 23:57
-
-
Save Isweet/2057ebfc0c8d87b0dc7aa09515f2a7ee to your computer and use it in GitHub Desktop.
Generate QR code and associated URL together in single image.
This file contains 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 sys | |
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
import qrcode | |
def concat_vertical(image1, image2): | |
w1, h1 = image1.size | |
w2, h2 = image2.size | |
w = max(w1, w2) | |
h = h1 + h2 | |
ret = Image.new('RGB', (w, h)) | |
ret.paste(image1, (0, 0)) | |
ret.paste(image2, (0, h1)) | |
return ret | |
def main(): | |
text = "www.google.com" | |
qr_i = qrcode.make(text) | |
text_i = Image.new('RGB', qr_i.size) | |
draw = ImageDraw.Draw(text_i) | |
font = ImageFont.truetype("Arial.ttf", 16) | |
draw.text((0, 0), text, (255, 255, 255), font=font) | |
final = concat_vertical(qr_i, text_i) | |
final.save('test.jpg') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment