1.批量实现二维码生成
首先需要一个TXT文档,每行是待生成二维码图片的信息,放在目录下
import qrcode
def generate_qr_code(data, output_file):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=100,
border=0,
)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.save(output_file)
if __name__ == "__main__":
fileHandler = open("123.txt", "r",encoding="UTF-8")
listOfLines = fileHandler.readlines()
fileHandler.close()
for line in listOfLines:
print(line.strip())
data_to_encode=line.strip()
output_file_path="./new"+line.strip()+".png"
generate_qr_code(data_to_encode, output_file_path)