您的位置:首页 > 编程语言 > Python开发

使用Python itchat个人微信账号头像拼接

2017-10-20 09:32 1041 查看
直接上代码

注:文件夹名字需要自己创建

需要安装:1.pip install itchat 2.pip install pillow

import itchat
import math
import PIL.Image as Image
import os

itchat.auto_login(hotReload=True)
friends = itchat.get_friends(update=True)[0:]
user = friends[0]["UserName"]
num = 0
for i in friends:
img = itchat.get_head_img(userName=i["UserName"])

fileImage = open('文件夹'+"/"+str(num)+".jpg", 'wb')
fileImage.write(img)
fileImage.close()
num += 1
ls = os.listdir('文件夹')
each_size = int(math.sqrt(float(640 * 640) / len(ls)))
lines = int(640 / each_size)
image = Image.new('RGB', (640, 640))
x = 0
y = 0
for 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 += 1
image.save("文件夹"+"/" + "all.jpg")
itchat.send_image("文件夹"+"/" + "all.jpg", 'filehelper')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 微信