Created
April 16, 2019 19:43
-
-
Save catichenor/a920922d3beb9bae9fcf9db2783cc814 to your computer and use it in GitHub Desktop.
Generate a QR code from text in an input file (also adds the text itself).
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
#!/usr/bin/env python | |
import os | |
import argparse | |
from pathlib import Path | |
import qrcode | |
from PIL import Image, ImageDraw, ImageFont | |
argparser = argparse.ArgumentParser() | |
argparser.add_argument("input", help="path to file containing text") | |
args = argparser.parse_args() | |
with open(args.input, 'r') as infile: | |
input_text = infile.read() | |
img = qrcode.make(input_text) | |
qr_pil = Image.new('RGB', (img.pixel_size, img.pixel_size), 'white') | |
qr_pil.paste(img, (0, 0)) | |
qr_text = ImageDraw.Draw(qr_pil) | |
qr_text.text((0, 0), input_text, (0, 0, 0)) | |
qr_savepath = str(Path.home() / "Pictures" / "qr.png") | |
qr_pil.save(qr_savepath) | |
os.startfile(qr_savepath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment