Python USES QRCode module to generate detailed two dimensional code examples

  • 2020-06-03 07:12:35
  • OfStack

Python USES the QRCode module to generate 2d codes

QRCode website

https://pypi.python.org/pypi/qrcode/5.1

Introduction to the

python-qrcode is a third module for generating 2d code images, which relies on the PIL module and the 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 values from 1 to 40 that controls the size of the 2-dimensional code (the minimum value is 1, a 12 by 12 matrix). If you want the program to determine automatically, set the value to None and use the fit parameter.

error_correction: Error correction function that controls 2d codes. The following four constants can be taken.
ERROR_CORRECT_L: approximately 7% or less errors can be corrected.
ERROR_CORRECT_M (default) : approximately 15% or less errors can be corrected.
ROR_CORRECT_H: approximately 30% or less errors can be corrected.

box_size: Controls the number of pixels contained in each cell in a 2-dimensional code.

border: The number of cells contained in the control border (the distance between the 2-d code and the image boundary) (the default is 4, which is the minimum specified by the relevant standard)

Thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: