zoukankan      html  css  js  c++  java
  • 【转】Python微信好友头像拼接图

      

      转自: Python微信好友头像拼接图

      今天在朋友圈看到有人发了微信好友拼接图,心里满是新奇,看了下评论才知道用Python写的。心里痒痒,立马就安装了下Python

      安装好了之后,看了下大神的代码,基本上能够读得懂(语言都是想通的嘛!),然后就尝试在小黑窗运行了,结果报错了!

    rawmode = RAWMODE[im.mode] KeyError: 'RGBA'

      这种错误看的我是一脸懵逼啊,搜索了半天也没看到什么解决方案,结果就在宁外一篇博客的评论里面发现了解决方法,结果成功运行,还是66的。

      

    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"]
    
    num = 0
    for i in friends:
        img = itchat.get_head_img(userName=i["UserName"])
        fileImage = open('D:' + "/wechat_head_image/" + str(num) + ".jpg",'wb')
        fileImage.write(img)
        fileImage.close()
        num += 1
    
    ls = os.listdir('D:/wechat_head_image')
    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('D:/wechat_head_image' + "/" + 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('D:/wechat_head_image/all' + "/" + "all.jpg")
    itchat.send_image('D:/wechat_head_image/all' + "/" + "all.jpg", 'filehelper')

      运行后效果截图

      

    不积跬步,无以至千里
  • 相关阅读:
    maven系列--eclipse的m2插件
    eclipse安装反编译插件
    maven系列--settings.xml
    maven系列--maven常用命令
    maven系列--maven目录
    centos 常用命令
    iis7.0 发生未知 FastCGI错误,错误代码 0x8007010b 的解决办法
    git 提交的步骤
    关于PHP函数传参的注意点
    关于SQL查询语句中的LIKE模糊查询的解释
  • 原文地址:https://www.cnblogs.com/wu-song/p/8026914.html
Copyright © 2011-2022 走看看