Making the QR code.
Let’s try another simple but useful Python use case and generate QR code for any desired link using qrcode library. In my example below I create code leading to my website.
A quick response or simply QR code is a special kind of barcode that can be read easily by different digital devices and which stores information as a series of pixels in a square-shaped grid.
Python Knowledge Base: Make coding great again.
- Updated:
2024-11-20 by Andrey BRATUS, Senior Data Analyst.
QR codes are frequently used to track information about web links (URLs) or just different products in a supply chain and often used for marketing/advertising purposes.
The result code usually consists of black modules arranged in a square pattern on a white background. The information encoded can be made up of any kind of data (e.g., binary, alphanumeric, etc).
QR code is detected by a 2-dimensional digital image sensor and then digitally analyzed by a programmed processor.
The main steps to generate QR code:
1 Install qrcode library.
2 Import the library.
3 Define address to be coded.
4 Define output type.
5 Export the image file.
#install qrcode library
# pip install qrcode
#Import qrcode library
import qrcode
#Define address to be coded
img = qrcode.make('https://python-code.pro/')
#Define output type
type(img) # qrcode.image.pil.PilImage
#Save qr code as png file
img.save("my_site_link.png")