How to Display name on QR code in openerp

2019-09-02 18:32发布

I have generated QR code in openerp using python. It's working successfully. But I Want to display name on qrcode Image. I tried to create in many way, but still i can not get solutions

Python:

a="Client Id: "+vals['client_id']+"\n"+"Client Name: "+vals['name']
qr = QRCode(version=20, error_correction=ERROR_CORRECT_L, box_size=2, border=2)
qr.add_data(a)
qr.make()
im = qr.make_image()
im.save("/home/cryosave_qrcodes/"+vals['client_id']+".png")

Generated QRcode this done by me

enter image description here

But I want show name on qrcode. like following image.

enter image description here Generated

I tried to create in many way, but still i can not get solutions Please anyone answer me

标签: qr-code
1条回答
太酷不给撩
2楼-- · 2019-09-02 18:58

This is one way: We can add text on qrcode, after qr generate.

from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw 
img = Image.open('sample.jpg')
#img = Image.new("RGBA",(100,150),(0,0,0))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/home/john/coda/Coda-Heavy.ttf", 20)
# draw.text((x, y),"Sample Text",(r,g,b))
draw.text((10,0),"Sample Text",(100,100,100), font=font)
img.save('/home/john/test.jpg')
查看更多
登录 后发表回答