Generate QR Code in python
QR codes have become an increasingly popular way of sharing information, and it’s easy to create one in Python using the qrcode library. In this article, we’ll show you how to generate and save a QR code into an image file, so you can share or use it later.
To get started, you’ll need to install the qrcode library using pip. For more information on the library, visit https://github.com/lincolnloop/python-qrcode.
Install the qrcode library
pip install qrcode
Next, import the qrcode library and create a QR code instance. Set the version, error correction level, box size, and border as desired.
Then, define the data that you want to store in the QR code, and add it to the instance. Finally, make the QR code, create an image from the instance, and save it as an image file with the extension of your choice.
Code:
# Import QR Code library
import qrcode
# Create qr code instance
qr = qrcode.QRCode(
version = 1,
error_correction = qrcode.constants.ERROR_CORRECT_H,
box_size = 10,
border = 2,
)
# The data that you want to store
data = "Message that you want to display"
# Add data
qr.add_data(data)
qr.make(fit=True)
# Create an image from the QR Code instance
img = qr.make_image()
# Save it somewhere, change the extension as needed:
img.save("image.png")
# img.save("image.bmp")
# img.save("image.jpeg")
# img.save("image.jpg")
QR codes can be used for a wide variety of purposes, from sharing URLs and contact information to product details and marketing campaigns. By generating and saving a QR code in Python, you can quickly and easily share information with others or use it yourself.
Customizing the appearance of the QR code is also easy with the qrcode library. You can change the colors, add a logo, or modify the size and shape of the QR code to suit your needs.
In conclusion, creating and saving a QR code in Python is a simple and efficient process. With the qrcode library, you can quickly generate QR codes for a variety of purposes and easily share them with others.
Here you can find the souce code on github repo