def _getqrtag(self, text, rect):
qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
qr.add_data(text)
qr.make(fit=True)
img = qr.make_image()
bio = io.BytesIO()
img.save(bio)
pngqr = bio.getvalue()
base64qr = base64.b64encode(pngqr)
#<image x="110" y="20" width="280px" height="160px" xlink:href="data:image/png;base64,……"/>
imagetag = ElementTree.Element("image")
imagetag.set("xlink:href", "data:image/png;base64,"+base64qr.decode("ascii"))
imagetag.set("x", str(rect.x))
imagetag.set("y", str(rect.y))
imagetag.set("width", str(rect.w))
imagetag.set("height", str(rect.h))
return imagetag
评论列表
文章目录