python生成二维码
- 2025-11-07 22:28:00
- admin
- 原创 39
一、pyqrcode生成二维码
1、pyqrcode代码仓库:https://github.com/mnooner256/pyqrcode
2、pyqrcode安装:pip.exe install pyqrcode,pip.exe install pypng
3、scale每个方块多少像素,quiet_zone边缘有几个空白方块;
4、容错率:L=7%、M=15%、Q=25%、H=30%,容错率越高,空间利用率越低;
5、编码方式:numeric、alphanumeric、binary、kanji,单个字符所用比特递增;
代码示例:
import pyqrcode
qr = pyqrcode.create('Some data', error='M', mode='binary')
qr.png('some_file0.png', scale=10)
qr.show(scale=10,quiet_zone=4)
print(qr.terminal())
二、qrcode生成二维码
1、qrcode代码仓库:https://github.com/lincolnloop/python-qrcode
2、qrcode安装:pip.exe install "qrcode[pil]"
3、box_size每个方块多少像素,border边缘有几个空白方块;
代码示例:
import qrcode
img = qrcode.make('Some data')
img.save('some_file1.png')
配置参数:
import qrcode
qr = qrcode.QRCode(version=1,box_size=10,border=4,
error_correction=qrcode.constants.ERROR_CORRECT_M)
qr.add_data('Some data')
qr.make(fit=True)
img = qr.make_image(fill_color='black', back_color='white')
img.save('some_file2.png')