如何用Python制作個(gè)性二維碼呢,比如制作有背景圖片的二維碼、或者是動(dòng)圖二維碼? 今天,梅朵就來(lái)給大家演示:Python制作此類個(gè)性二維碼的方法! 主要是準(zhǔn)備背景圖片和GIF動(dòng)圖。 2.導(dǎo)入依賴庫(kù) 主要是導(dǎo)入二維碼生成依賴庫(kù)MyQR。 3.生成個(gè)性二維碼 調(diào)用myqr.run函數(shù)生成個(gè)性二維碼。 myqr.run(words='Welcome to our official account: Excel-Python', picture=r'C:\Users\Administrator\Desktop\Excel-Python.jpg', colorized=True, save_name='My_QR_code.png', save_dir=r'C:\Users\Administrator\Desktop')
myqr.run(words='Welcome to our official account: Excel-Python', picture=r'C:\Users\Administrator\Desktop\mouse.gif', colorized=True, save_name='My_QR_code.gif', save_dir=r'C:\Users\Administrator\Desktop') 4.補(bǔ)充:對(duì)二維碼進(jìn)行解析可導(dǎo)入二維碼解析依賴庫(kù)zxing,調(diào)用myqr.run函數(shù)對(duì)二維碼信息進(jìn)行解析。 import random from PIL import Image import os import zxing
filename=r'C:\Users\Administrator\Desktop\My_QR_code.png' img = Image.open(filename) ran = int(random.random() * 100000) img.save('%s%s.png' % (os.path.basename(filename).split('.')[0], ran)) reader = zxing.BarCodeReader() barcode = reader.decode('%s%s.png' % (os.path.basename(filename).split('.')[0], ran)) print(barcode)
是不是很簡(jiǎn)單,幾行代碼就能搞定,喜歡的小伙伴趕緊試試吧!
from MyQR import myqr
myqr.run(words='Welcome to our official account: Excel-Python', picture=r'C:\Users\Administrator\Desktop\Excel-Python.jpg', colorized=True, save_name='My_QR_code.png', save_dir=r'C:\Users\Administrator\Desktop')
myqr.run(words='Welcome to our official account: Excel-Python', picture=r'C:\Users\Administrator\Desktop\mouse.gif', colorized=True, save_name='My_QR_code.gif', save_dir=r'C:\Users\Administrator\Desktop')
import random from PIL import Image import os import zxing
filename=r'C:\Users\Administrator\Desktop\My_QR_code.png' img = Image.open(filename) ran = int(random.random() * 100000) img.save('%s%s.png' % (os.path.basename(filename).split('.')[0], ran)) reader = zxing.BarCodeReader() barcode = reader.decode('%s%s.png' % (os.path.basename(filename).split('.')[0], ran)) print(barcode)
|