微信将你所有的好友头像拼接成一张图片

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')
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一次捧读张爱玲的小说,总不免带着几分好奇与恐惧。好奇的自然是她如何在人物身上杂糅进她与胡兰成的爱恨纠葛,恐...
    小乔流水谁家阅读 224评论 0 0
  • “因为一般陌生人说话总是说天气”“那我们是陌生人”“可我们还没有说天气”“乌镇的天气确实比台北冷呵” 因为一条新闻...
    毛欣与小李阅读 630评论 0 0
  • 吃过午饭昏昏沉沉的我准备在办公室桌上趴着小睡会儿,按照常理刷个朋友圈,可是今天下拉刷新动态如果不是我没垫下巴那我估...
    麻辣蘑菇酱阅读 382评论 0 0
  • 一晃,八天没记什么了。 债多不压身。很多值得记录的都没时间追溯了。想到哪是哪吧。 敖厂长也分析了一波贪玩蓝月 分享...
    alucardzhou阅读 131评论 0 0