Practice using Python to write two-dimensional code applet;
Need to install Python's QR code library--QRCode
Pip Install QRCode
The code is as follows:
#Coding=utf-8ImportQRCode
#a = Qrcode.make (' http://www.baidu.com ') #默认生成的二维码#a.save (' QR code _ Baidu. png ')qr=QRCode. QRCode (Version=1, Error_correction=QRCode. Error_correct_q, Box_size=4, Border=2) Qr.add_data ('http://www.baidu.com/') Qr.make (Fit=True) img= Qr.make_image (fill_color='Yellow', back_color='Blue') Img.save ('Two-dimensional code _ Baidu. PNG')
The parameter version indicates the size of the generated two-dimensional code, the value range is 1 to, the 40 smallest size 1 will generate 21 * 21 a QR code, version each increase 1 , the resulting QR code will be added to the 4 dimension,
For version example 2 , the resulting 25 * 25 two-dimensional code.
The parameter error_correction specifies the fault tolerance coefficients for the two-dimensional code, respectively, with the following 4 coefficients:
-
ERROR_CORRECT_L: 7% of Loadline can be fault tolerant
-
ERROR_CORRECT_M: 15% of Loadline can be fault tolerant
-
ERROR_CORRECT_Q: 25% of Loadline can be fault tolerant
-
ERROR_CORRECT_H: 30% of Loadline can be fault tolerant
box_sizethe parameter represents the pixel size of each lattice in the QR code.
borderThe parameter indicates how much the border's lattice thickness is (by default 4 ).
The resulting QR code is as follows:
QR code generated by default:
Set the QR code generated by the dimension color:
Python generates two-dimensional code