Skip to content

Instantly share code, notes, and snippets.

@nhoffman
Created September 11, 2024 18:33
Show Gist options
  • Save nhoffman/86f1c6ff49996097c4b0c48eb9fc7374 to your computer and use it in GitHub Desktop.
Save nhoffman/86f1c6ff49996097c4b0c48eb9fc7374 to your computer and use it in GitHub Desktop.
Create a QR Code
#!/usr/bin/env python3
"""Create a QR Code
"""
import os
import sys
import argparse
import qrcode
def main(arguments):
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('url')
parser.add_argument('-o', '--outfile', help="Output file",
default='qrcode.png')
args = parser.parse_args(arguments)
# Create an instance of QRCode
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
# Add the URL data to the QR code
qr.add_data(args.url)
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image(fill='black', back_color='white')
# Save the image to a file
img.save(args.outfile)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment