Created
March 28, 2026 16:07
-
-
Save ShijianXu/002c6d30858e61d058ed89265c7caee8 to your computer and use it in GitHub Desktop.
Code to generate a QR code based on the url input
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 python3 | |
| import argparse | |
| import qrcode | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Generate a QR code from a URL") | |
| parser.add_argument("url", help="URL to encode in the QR code") | |
| parser.add_argument( | |
| "-o", "--output", | |
| default="qrcode.png", | |
| help="Output PNG file path (default: qrcode.png)" | |
| ) | |
| args = parser.parse_args() | |
| qr = qrcode.QRCode( | |
| error_correction=qrcode.constants.ERROR_CORRECT_L, | |
| box_size=10, | |
| border=4, | |
| ) | |
| qr.add_data(args.url) | |
| qr.make(fit=True) | |
| img = qr.make_image(fill_color="black", back_color="white") | |
| img.save(args.output) | |
| print(f"QR code saved to {args.output}") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment