如何在PYTHON的Qrcode中间插入徽标? [英] How to insert logo in the center of qrcode in Python?

查看:25
本文介绍了如何在PYTHON的Qrcode中间插入徽标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python中的pyqrcode模块,并用它生成二维码。如何将徽标放在该二维码的中心。

代码如下

import pyqrcode
data = "Hello World!!"

number = pyqrcode.create(data)
number.png('xyz.png', scale=int(scale))

with open('xyz.png', "rb") as f:
    return HttpResponse(f.read(), content_type="image/png")

或者有没有其他方法来替代pyqrcode?

推荐答案

如果您使用高冗余算法(如H),则会对生成的二维码造成一定百分比的损坏。H表示您可以覆盖30%的数据,但它仍然有效。

这意味着只需将图像放在代码上即可。格式由您决定。

import pyqrcode
from PIL import Image
url = pyqrcode.QRCode('http://www.eqxiu.com',error = 'H')
url.png('test.png',scale=10)
im = Image.open('test.png')
im = im.convert("RGBA")
logo = Image.open('logo.png')
box = (135,135,235,235)
im.crop(box)
region = logo
region = region.resize((box[2] - box[0], box[3] - box[1]))
im.paste(region,box)
im.show()

这篇关于如何在PYTHON的Qrcode中间插入徽标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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