【问题标题】:How to export qr_code img to disk?如何将 qr_code img 导出到磁盘?
【发布时间】:2019-03-05 17:01:01
【问题描述】:

我使用python包qrcode从url生成二维码图片:

url='www.google.com'
qr = qrcode.QRCode(version=1,
                   error_correction=qrcode.constants.ERROR_CORRECT_L,
                   box_size=10,
                   border=4)

qr.add_data(url)
qr.make(fit=True)
img = qr.make_image()
return img

如何将img保存到磁盘的某个路径?

我试过了:

image_file = open(path_qr_code, 'w')
image_file.write(img)
image_file.close

但我明白了:

TypeError: write() 参数必须是 str,而不是 PilImage

【问题讨论】:

标签: python-3.x save qr-code


【解决方案1】:

TypeError: write() 参数必须是 str,而不是 PilImage

这表示imgPilImage的类型,那么你可以使用saving a PilImage的方式来保存它。例如,

img.save(path_qr_code)

【讨论】:

    猜你喜欢
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多