2026-02-24 14:02:05 +08:00

17 lines
500 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import qrcode
def gen_qr(data, path):
qr = =qrcode.QRCode(
version=1, # 控制二维码大小1~40
error_correction=qrcode.constants.ERROR_CORRECT_L, # 容错率 L(7%)、M(15%)、Q(25%)、H(30%)
box_size=10, # 每个格子的像素大小
border=4, # 边框宽度最小为4
)
qr.add_data(data)
qr.make(fit=True) # 自动调整版本以适应数据
# 生成图像
img = qr.make_image(fill_color="black", back_color="white")
img.save(path)