-- coding: utf-8 --
“”"
pip install image
pip install qrcode
author= ‘haiousy@’
生成带Logo二维码
测试环境 Anaconda3
“”"
from PIL import Image
import qrcode
qr = qrcode.QRCode(version=5,error_correction=qrcode.constants.ERROR_CORRECT_H,box_size=8,border=1)
qr.add_data(“”)#要生成二维码的内容
qr.make(fit=True)
img = qr.make_image()
img = img.convert(“RGBA”)
icon = Image.open(“jcelogo.png”) #logo图片默认在当前py文件目录下
img_w,img_h = img.size
factor = 4
size_w = int(img_w / factor)
size_h = int(img_h / factor)
icon_w,icon_h = icon.size
if icon_w >size_w:
icon_w = size_w
if icon_h > size_h:
icon_h = size_h
icon = icon.resize((icon_w,icon_h),Image.ANTIALIAS)
w = int((img_w - icon_w)/2)
h = int((img_h - icon_h)/2)
icon = icon.convert(“RGBA”)
img.paste(icon,(w,h),icon)
#img.save(‘jceerweima.png’)
img.show()
“”"
生成带Logo二维码
“”"
如果觉得《python 生成带logo二维码》对你有帮助,请点赞、收藏,并留下你的观点哦!