Home >Backend Development >Python Tutorial >Detailed example of how Python uses the QRCode module to generate QR codes
This article mainly introduces PythonRelated information on using the QRCode module to generate QR code examples. Friends in need can refer to
Python uses the QRCode module to generate QR codes. QR code
QRCode official website
https://pypi.python.org/pypi/qrcode/5.1
python-qrcode is a third-party module used to generate QR codes pictures, relying on the PIL module and qrcode library .
Simple usage
import qrcode img = qrcode.make('hello, qrcode') img.save('test.png')
Advanced usage
import qrcode qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('hello, qrcode') qr.make(fit=True) img = qr.make_image() img.save('123.png')
Parameter meaning:
version: integer with a value from 1 to 40, controlling the size of the QR code (the minimum value is 1, is a 12×12 matrix). If you want the program to determine this automatically, set the value to None and use the fit argument.
error_correction: Control the error correction function of QR code. The following 4 constants can be taken as values.
ERROR_CORRECT_L: About 7% or less of errors can be corrected.
ERROR_CORRECT_M (default): About 15% or less of errors can be corrected.
ROR_CORRECT_H: About 30% or less of errors can be corrected.
box_size: Controls the number of pixels contained in each small grid in the QR code.
border: Control the number of grids included in the border (the distance between the QR code and the image border) (the default is 4, which is the minimum value specified by relevant standards)
The above is the detailed content of Detailed example of how Python uses the QRCode module to generate QR codes. For more information, please follow other related articles on the PHP Chinese website!