Skip to content

Instantly share code, notes, and snippets.

@tinshade
Created February 6, 2021 10:30
Show Gist options
  • Select an option

  • Save tinshade/73be5605f212c3a2fe8e4719826bdda4 to your computer and use it in GitHub Desktop.

Select an option

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!
###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