1、itchat之把所有微信好友的头像生成拼图
问题:如何处理好友图像大小为0的异常?img = itchat.get_head_img(userName=i["UserName"]
新建目录
c:\sbin\head\image
把代码放在
head
目录下,git bash运行安装pip install itchat
和pip install pillow
代码:把
'C:/Users/LP/Desktop/image'
和中文'文件夹路径'
用相对路径./image'
替换
git bash运行代码,可以生成二维码并顺利下载好友头像,但是有的头像文件大小是0,在拼接阶段报错。
拼图大小不能局限于640,会出黑边,因此计算出一个接近的img_size
即可,问题是好友越多,没有纳入拼图的越多。几条print语句是为了调试方便
以下是生成拼图的部分程序代码all.py
:
import math
from PIL import Image
import os
ls = os.listdir(‘./image’)
each_size = int(math.sqrt(float(640640)/len(ls)))
lines = int(640/each_size)
print(‘Total ‘ + str(len(ls)) + ‘ images and ‘ + str(lines) + ‘ lines ‘ + str(each_size) + ‘ pixels’)
img_size = lines each_size
image = Image.new(‘RGB’, (img_size , img_size))
x = 0
y = 0
img_count = lines lines
for i in range(0,img_count):
try:
img = Image.open(‘./image/‘ + str(i) + “.jpg”)
except IOError:
print(“Error” + str(i))
else:
img = img.resize((each_size, each_size), Image.ANTIALIAS)
image.paste(img, (x each_size, y * each_size))
x += 1
if x == lines:
print(‘Line ‘ + str(y+1) + ‘ done!’)
x = 0
y += 1
image.save(‘all.jpg’)
itchat+pillow实现微信好友头像爬取和拼接 #另一个几乎相同的实现,下载了好多奇怪的安装包。也是因为有个好友头像文件大小是0,报错退出。这个好友是把我删除了吧?
python微信开源接口
itchatmp #开源的微信公众号、企业号接口
wxBot #python2版本,但是有图灵机器人很好玩,可以陪聊天啊
一件有趣的事:我用 Python 爬了爬自己的微信朋友
Python itchat包分析微信好友
python使用itchat库实现微信机器人
python实现微信接口(itchat) #hotReload==True
参数似乎已经不支持了
Python图像处理库Pillow入门