同步操作将从 小柒2012商城/从零学Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from wxpy import *import mathfrom PIL import Imageimport os# 创建头像存放文件夹def create_filePath():avatar_dir = os.getcwd() + "\\wechat\\"if not os.path.exists(avatar_dir):os.mkdir(avatar_dir)return avatar_dir# 保存好友头像def save_avatr(avatar_dir):# 初始化机器人,扫码登录bot = Bot()friends = bot.friends(update=True)num = 0for friend in friends:friend.get_avatar(avatar_dir + '\\' + str(num) + ".jpg")print('好友昵称:%s' % friend.nick_name)num = num + 1# 拼接头像def joint_avatar(path):# 获取文件内头像个数length = len(os.listdir(path))# 设置画布大小# image_size = 2500# 设置每个头像大小each_size = math.ceil(2560 / math.floor(math.sqrt(length)))# 计算所需各行列的头像数量x_lines = math.ceil(math.sqrt(length))y_lines = math.ceil(math.sqrt(length))image = Image.new('RGB', (each_size * x_lines, each_size * y_lines))x = 0y = 0for(root, dirs, files) in os.walk(path):for pic_name in files:# 增加头像读不出来的异常处理try:with Image.open(path + pic_name) as img:img = img.resize((each_size, each_size))image.paste(img, (x * each_size, y * each_size))x += 1if x == x_lines:x = 0y += 1except IOError:print("头像读取失败")image.save(os.getcwd() + "/wechat.png")print('微信好友头像拼接完成!')if __name__ == '__main__':avatar_dir = create_filePath()save_avatr(avatar_dir)joint_avatar(avatar_dir)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。