The pyqrcode module is a QR code generator that is simple to use and written in pure python.
pip install pyqrcode
import pyqrcode
# a simple example of creating a QR code for a URL
url = pyqrcode.create("http://uca.edu")
# svg格式
url.svg("uca-url.svg", scale=8)
# EPS格式
url.eps("uca-url.eps", scale=2)
# terminal输出
print(url.terminal(quiet_zone=1))
import pyqrcode
big_code = pyqrcode.create("0987654321", error="L", version=27, mode="binary")
# create(content, error='H', version=None, mode=None, encoding=None)
# 返回一个QRCode实例对象
# error: sets the error correction level of the code 设置代码数据修正程度
# 一个有四种程度: "L", "M", "Q", "H"
# version ---> int (1-40)
# specifies the size and data capacity of the code 指定代码的大小和数据容量
# mode --->str
# specifies how the contents will be encoded. 指定代码内容使用什么编码格式
# "numeric", "alphanumeric", "kanji", "binary"
# encoding --->
# specifies how the content will be interpreted 指出内容将怎样解析
big_code.png("code.png", scale=6, module_color=[0,0,0,128],background=[0xff,0xff,0xcc])
big_code.show()
链接:https://pythonhosted.org/PyQRCode/
eps
(file, scale=1, module_color=(0, 0, 0), background=None, quiet_zone=4) png
(file, scale=1, module_color=(0, 0, 0, 255), background=(255, 255, 255, 255), quiet_zone=4) svg
(file, scale=1, module_color='#000', background=None, quiet_zone=4, xmldecl=True, svgns=True, title=None, svgclass='pyqrcode', lineclass='pyqrline', omithw=False, debug=False)