最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

分享Python如何实现头像拼接技术/

来源:动视网 责编:小采 时间:2020-11-27 14:14:07
文档

分享Python如何实现头像拼接技术/

分享Python如何实现头像拼接技术/:微信好友全头像话不多说,直接上代码import itchat import math import PIL.Image as Image import os itchat.auto_login() friends = itchat.get_friends(update=True)[0:] user = friends[0]["Us
推荐度:
导读分享Python如何实现头像拼接技术/:微信好友全头像话不多说,直接上代码import itchat import math import PIL.Image as Image import os itchat.auto_login() friends = itchat.get_friends(update=True)[0:] user = friends[0]["Us

微信好友全头像

话不多说,直接上代码

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 = 0for i in friends:
 img = itchat.get_head_img(userName=i["UserName"])
 fileImage = open('文件夹' + "/" + str(num) + ".jpg",'wb')
 fileImage.write(img)
 fileImage.close()
 num += 1ls = os.listdir('文件夹')
each_size = int(math.sqrt(float(640*640)/len(ls)))
lines = int(640/each_size)
image = Image.new('RGBA', (640, 640))x = 0y = 0for 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 += 1if x == lines:x = 0y += 1
image.save('文件夹' + "/" + "all.jpg")
itchat.send_image('文件夹' + "/" + "all.jpg", 'filehelper')

代码运行需要安装两个库

pip install itchat
pip install pillow

如果安装python的时候pip安装选项没打√ ,就先安装pip。
Python和pip的安装


itchat官方介绍

代码运行过程中会出现登录二维码,用微信扫一下,你就可以看到处理的进度。一会你的微信文件传输助手就会收到拼接好的头像图片。

学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入学习交流群

文档

分享Python如何实现头像拼接技术/

分享Python如何实现头像拼接技术/:微信好友全头像话不多说,直接上代码import itchat import math import PIL.Image as Image import os itchat.auto_login() friends = itchat.get_friends(update=True)[0:] user = friends[0]["Us
推荐度:
标签: 分享 头像 好友
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top