如何将 qr_code img 导出到磁盘? [英] How to export qr_code img to disk?

查看:71
本文介绍了如何将 qr_code img 导出到磁盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I generate a qr code image from an url using the python package qrcode:

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保存到磁盘的某个路径?

How do I save the img to the disk at a certain path ?

我试过了:

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

但我明白了:

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

TypeError: write() argument must be str, not PilImage

推荐答案

试试这个:

img.save("img.png","PNG")

或带路径:

img.save(path_qr_code + "\\" + "imgtest.png","PNG")

这篇关于如何将 qr_code img 导出到磁盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆