美文网首页
微信将你所有的好友头像拼接成一张图片

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

作者: ifqu | 来源:发表于2018-06-13 10:37 被阅读0次
    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')
    

    相关文章

      网友评论

          本文标题:微信将你所有的好友头像拼接成一张图片

          本文链接:https://www.haomeiwen.com/subject/yqxjeftx.html