这里有新鲜出炉的Python教程,程序狗速度看过来!
Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。
下面小编就为大家带来一篇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]["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('文件夹')
- 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('文件夹' + "/" + 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')
代码运行需要安装两个库
pip install itchat
pip install pillow
如果安装python的时候pip安装选项没打√ ,就先安装pip。
Python和pip的安装
itchat官方介绍
代码运行过程中会出现登录二维码,用微信扫一下,你就可以看到处理的进度。一会你的微信文件传输助手就会收到拼接好的头像图片。
以上这篇Python实现好友全头像的拼接实例(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持PHPERZ。
来源: http://www.phperz.com/article/17/1029/351325.html