Summarize the example code for using QRCode to generate QR codes in Python

零下一度
Release: 2017-06-17 11:22:49
Original
1472 people have browsed it

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

pypi.python.org/pypi/qrcode/5.1

Introduction

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')
Copy after login

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')
Copy after login

Parameter meaning :

version: integer with a value from 1 to 40, controlling the size of the QR code (the minimum value is 1, which 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 Summarize the example code for using QRCode to generate QR codes in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template