if __name__ == '__main__': version, level, qr_name = myqr.run( words='https://xxx.com/ccc', version=1, level='H', picture='./XKD.gif', colorized=True, contrast=1.0, brightness=1.0, save_name='test4.gif', save_dir=os.getcwd() )print(version)print(level) print(qr_name)MyQR確實是挺好用的,唯一的缺點就是,不支持中文!!!沒錯,是不是有點遺憾,它只支持以下字符:3. qrcodeqrcode的功能雖稍遜於MyQR,但是它支持中文字符,且能生成矢量圖,安裝命令如下:def mergeImg(img1, img2, flag=True):""" 合併圖像 :param img1: :param img2: :param flag: True 表示將logo居中, False 表示將logo作為背景圖 :return: """ img1_w, img1_h = img1.sizeif flag: img2_w = int(img2.size[0] / 3) img2_h = int(img2.size[1] / 3)# 縮放logo img2 = img2.resize(size=(img2_w, img2_h), resample=Image.ANTIALIAS)# 將logo居中顯示 img1.paste(im=img2, box=(int((img1_w - img2_w) / 2), int((img1_h - img2_h) / 2))) img1.save('./test8.png')else: img2 = img2.resize(size=(img1_w, img1_h), resample=Image.ANTIALIAS)# 兩張圖片的size和mode要一致# 計算公式為out = image1 * (1.0 - alpha) + image2 * alpha# 這裡的背景色就是一種幹擾了, 如果將二維碼的透明度設置過高會識別不出來 out_img = Image.blend(img1, img2, alpha=0.3) out_img.save('./test9.png')
if __name__ == '__main__': qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=10, border=4, ) qr.add_data('https://xxx.com/ccc') qr.make(fit=True)
# black green purple orange pink white blue# make_image() 返回的是一個PilImage對象# 可以使用pillow對它進行圖像處理相關的操作# img1 = qr.make_image(fill_color="#8A2BE2", back_color="white") img1 = qr.make_image(fill_color="orange", back_color="white").convert('RGB')# img1.show()# img1.save('./test6.png')
img2 = Image.open('./cutcamera.png').convert('RGB') mergeImg(img1, img2, flag=True)如有文章對你有幫助,
「在看」和轉發是對我最大的支持!
關注Python極客專欄