參考自:http://www.reibang.com/p/684cbdf15874
思路就是通過itchat登錄獲取微信好友信息寄摆,然后通過pillow畫圖
import itchat
import math
import PIL.Image as Image
import os
# hotReload=True # 使用這個(gè)屬性已卸,生成一個(gè)靜態(tài)文件itchat.pkl惧磺,用于存儲(chǔ)登陸的狀態(tài)旋讹。
itchat.auto_login(hotReload=True)
friends = itchat.get_friends(update=True)[0:]
path = 'G:/python/image/'
for item in friends:
# 可以打印item來看其中具體是什么內(nèi)容,有什么字段
img = itchat.get_head_img(userName=item['UserName'])
with open(path + item['NickName'] + '.jpg', 'wb') as f:
f.write(img)
# 獲取好友昵稱和簽名
info = [(item['NickName'], item['Signature']) for item in friends]
# 獲取文件夾中所有的圖片
ls = os.listdir(path)
img_num = len(ls)
# 每張小圖片寬
size = 60
#每行放幾張
lines = 10
# 大圖寬
width = 600
# 大圖長(zhǎng)
height = math.ceil(img_num/10)*60
# 畫一個(gè)大圖夏醉,用來放小頭像
image = Image.new('RGBA', (width, height))
x = 0
y = 0
for i in range(0, len(ls)):
img = Image.open(path + info[i][0] + '.jpg')
img = img.resize((size, size), Image.ANTIALIAS)
# 向指定位置放縮小后的圖片
image.paste(img, (x * size, y * size))
x += 1
if x == lines:
x = 0
y += 1
image.save(path + 'friends.jpg')
# 通過文件助手發(fā)給自己
itchat.send_image(path + 'friends.jpg', 'filehelper')