前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信好友全头像直接上图代码代码分析

微信好友全头像直接上图代码代码分析

作者头像
罗罗攀
发布2018-07-03 14:00:10
4980
发布2018-07-03 14:00:10
举报

直接上图

代码

代码语言:javascript
复制
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('文件夹路径' + "/" + str(num) + ".jpg",'wb')
    fileImage.write(img)
    fileImage.close()
    num += 1

ls = os.listdir('C:/Users/LP/Desktop/image')
each_size = int(math.sqrt(float(640*640)/len(ls)))
lines = int(640/each_size)
image = Image.new('RGBA', (640, 640))
x = 0
y = 0
for i in range(0,len(ls)+1):
    try:
        img = Image.open('C:/Users/LP/Desktop/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('C:/Users/LP/Desktop/image' + "/" + "all.jpg")
itchat.send_image('C:/Users/LP/Desktop/image' + "/" + "all.jpg", 'filehelper')

代码分析

首先下载图片,最后通过piilow拼接起来

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.04.15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 直接上图
  • 代码
  • 代码分析
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档