Python QR Codes
Fri 15 April 2022As we stopped wanting to touch each other and things during the Covid-19 pandemic, QR Codes became ubiquitous.
I can't think of anyone who has had a better year than the QR code. What a comeback.
— Grace Mulvey (@GraceMulvey1) December 17, 2021
As I'm planning a few upcoming virtual lightning talks at the Cloud-Native Geospatial Outreach Event that include unsightly links, I'm preparing a few QR codes that (hopefully?) the audience will be able to use rather than copy/pasting links during my talks.
Anyway, creating QR codes with Python is easy, thanks to the qrcode module. Here's how I created a QR code pointing to this page:
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers import RoundedModuleDrawer
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
qr.add_data('https://darrenwiens.github.io/python-qr-codes.html')
img = qr.make_image(
image_factory=StyledPilImage,
embeded_image_path="/path/to/image.png",
module_drawer=RoundedModuleDrawer()
)
img.save("qr-code-blog.png")
And the result:
Get in touch with me on Twitter if you want to talk about it!