#-*-coding:utf-8-*-#@Author: FELIX#@Date: 2018/5/18 16:19ImportQRCode fromPILImportImageurl='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)#Add InformationQr.make (fit=True) img=qr.make_image () img=img.convert ('RGBA')#im = Image.open (r "cc.jpg")#Im.save (r "C2.png")#when adding logo, the format of the logo is PNG, otherwise it will be errorIcon=image.open ('Ab.png') Img_w,img_h=Img.sizefactor=5#scale, too small may not be recognizedSize_w=int (img_w/factor) Size_h=int (img_h/factor) Icon_w,icon_h=icon.sizeifIcon_w >Size_w:icon_w=Size_wifIcon_h >Size_h:icon_h=Size_hicon=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')
Python generates two-dimensional code