我正在尝试使用以下代码在 Django 应用程序上使用 Python 制作二维码:
def generate_qr_code (reference):
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4,
)
qr.add_data(reference)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white").convert('RGB')
filename = reference+".jpeg"
img.save("C:\\qrs\\"+filename)
现在,当我单击“生成二维码”按钮时,将调用此函数。我的问题是,我希望二维码显示在浏览器的新选项卡上,而不是保存为图像,因为当时我只需要将它们打印在纸上,不需要保留图像。
感谢您的帮助。
将图像转换为 base64 并在 html 中显示像这样 https://stackoverflow.com/questions/20756042/how-to-display-an-image-stored-as-byte-array-in-html-javascript
import base64
b64 = base64.b64encode(image).decode("utf-8")
update:
ofc 您不需要将图像保存为 png 来使用此功能,您可以更改 html 中的格式,也可以更改图像格式而不将其保存到文件中像这样 https://stackoverflow.com/questions/56564977/encoding-a-numpy-array-image-to-an-image-type-png-etc-to-use-it-with-the-gcl
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)