Using the Python QRCode module, generate two-dimensional code

A general two-dimensional code
 

import qrcode
img = qrcode.make('https://blog.csdn.net/u013380694')
img.save('cby.png')

Senior two-dimensional code

We use, you can also define some other parameters to use some advanced usage:

import qrcode
qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,
)
qr.add_data('https://blog.csdn.net/u013380694')
qr.make(fit=True)
img = qr.make_image()
img.save('cby.png')

 

Three-parameter interpretation 

version: an integer ranging from 1 to 40, represents the size of the two-dimensional code (the minimum value is 1, is a matrix of 12 × 12), if you want True parameters automatically generated, and the value to use fit = None i.e. can.

error_correction: two-dimensional code is an error correction range may be selected four constants

  • ERROR_CORRECT_L 7% or less of the error will be corrected
  • ERROR_CORRECT_M (default) 15% or less of the error will be corrected
  • ERROR_CORRECT_Q 25% or less of the error will be corrected
  • ERROR_CORRECT_H. 30% or less of the error will be corrected

The number of pixels per dot (block) of: boxsize

border: two-dimensional code from the image frame from the periphery, the default is 4, and the relevant provisions of a minimum of 4

 

Reference  https://pypi.org/project/qrcode/5.1/

Published 43 original articles · won praise 28 · views 40000 +

Guess you like

Origin blog.csdn.net/u013380694/article/details/101301058