python生成二维码
# -*- coding: utf-8 -*- # @Author : FELIX # @Date : 2018/5/18 16:19 import qrcode from PIL import Image url='http://www.baidu.com' qr=qrcode.QRCode( version=2, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=8, border=2 ) qr.add_data(url) # 添加信息 qr.make(fit=True) img=qr.make_image() img=img.convert('RGBA') # im = Image.open(r"cc.jpg") # im.save(r"c2.png") # 添加logo时logo的格式为png,不然会报错 icon=Image.open('ab.png') img_w,img_h=img.size factor=5 # 比例,过小可能无法识别 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) img.paste(icon, (w, h), icon) # img=qrcode.make('http://www.baidu.com') img.save('test.png')
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16