美文网首页
微信拼图

微信拼图

作者: 阅读专家 | 来源:发表于2017-11-07 10:56 被阅读0次
    
    import itchat
    import math
    import PIL.Image as Image
    import os
    itchat.auto_login()
    friends = itchat.get_friends(update=True)[0:]
    user = friends[0]["UserName"]
    os.makedirs('d:\\image1')
    os.chdir('d:\\image1')
    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')
    
    

    相关文章

      网友评论

          本文标题:微信拼图

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