Created
February 6, 2021 10:30
-
-
Save tinshade/73be5605f212c3a2fe8e4719826bdda4 to your computer and use it in GitHub Desktop.
This simple gist demonstrates the use of third-party QR Code packages with Python3 to generate and decode QR Codes and Bar Codes alike!
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
| ###Generating a QR Code### | |
| #pip install pyqrcode | |
| #`pip install pypng` for PNG import errors, or try reinstalling Pillow! | |
| import pyqrcode | |
| from PIL import Image | |
| s = "www.geeksforgeeks.org" | |
| url = pyqrcode.create(s) | |
| #url.svg("myqr.svg", scale = 8) | |
| url.png("code.png", scale=8) #Creates QR code PNG image in the current working directory! | |
| ###Decoding a QR Code## | |
| #pip install pyzbar | |
| #pip install pillow | |
| from pyzbar.pyzbar import decode as qr_decode | |
| from PIL import Image | |
| data = qr_decode(Image.open('code.png')) | |
| # To get the data | |
| print(data) | |
| # To get the message | |
| print(data[0][0].decode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment