
微信好友全頭像
話不多說,直接上代碼
import itchatimport mathimport PIL.Image as Imageimport ositchat.auto_login()friends = itchat.get_friends(update=True)[0:]user = friends[0]["UserName"]num = 0for i in friends: img = itchat.get_head_img(userName=i["UserName"]) fileImage = open('文件夾' + "/" + str(num) + ".jpg",'wb') fileImage.write(img) fileImage.close() num += 1ls = os.listdir('文件夾')each_size = int(math.sqrt(float(640*640)/len(ls)))lines = int(640/each_size)image = Image.new('RGBA', (640, 640))x = 0y = 0for i in range(0,len(ls)+1): try: img = Image.open('文件夾' + "/" + str(i) + ".jpg") except IOError: print("Error") else: img = img.resize((each_size, each_size), Image.ANTIALIAS) image.paste(img, (x * each_size, y * each_size)) x += 1 if x == lines: x = 0 y += 1image.save('文件夾' + "/" + "all.jpg")itchat.send_image('文件夾' + "/" + "all.jpg", 'filehelper')代碼運行需要安裝兩個庫
pip install itchat
pip install pillow
如果安裝python的時候pip安裝選項沒打√ ,就先安裝pip。
Python和pip的安裝

itchat官方介紹
代碼運行過程中會出現登錄二維碼,用微信掃一下,你就可以看到處理的進度。一會你的微信文件傳輸助手就會收到拼接好的頭像圖片。
以上這篇Python實現好友全頭像的拼接實例(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答