微信将你所有的好友头像拼接成一张图片
2018-06-13 本文已影响0人
ifqu
import itchat
import os
import math
import PIL.Image as Image
itchat.auto_login()
frinds=itchat.get_friends(update=True)[0:]
print(frinds)
user=frinds[0]['UserName']
num=0
os.mkdir(user)
for i in frinds:
img=itchat.get_head_img(i["UserName"])
fileIamge=open(user+'/'+str(num)+'.jpg','wb')
fileIamge.write(img)
fileIamge.close()
num+=1
pics=os.listdir(user)
pics=os.listdir(user)
numPic=len(pics)
print(numPic)
eachsize=int(math.sqrt(float(640*640) / numPic))
numline=int(640 / eachsize)
toImage=Image.new('RGBA',(640,640))
x=0
y=0
for i in pics:
try:
img = Image.open(user + "/" + i)
except IOError:
print("Error: 没有找到文件或读取文件失败")
else:
img = img.resize((eachsize, eachsize), Image.ANTIALIAS)
toImage.paste(img, (x * eachsize, y * eachsize))
x += 1
if x == numline:
x = 0
y += 1
toImage.save(user+'.png')
itchat.send_image(str(user)+'.png','filehelper')