如何在Python中的qrcode的中心插入徽标?
问题描述:
我在Python中使用pyqrcode模块,并用它生成qr代码。如何将徽标放在该qr码的中心。如何在Python中的qrcode的中心插入徽标?
代码看起来像这样
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")
或者是还有什么做的aother方式这insted的pyqrcode的?
答
from pyqrcode import QRCode
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 PIL另一图像?](https://stackoverflow.com/questions/2563822/how-do-you-composite -o-image-into-another-image-with-pil-in-python) – iFlo
你不觉得qr代码会产生问题,如果我这样做? –