知识来源:/p/73975013
1.环境
os:MAC
tool:python 3.7 ,pip3.7
2.前提:
使用pip3.7 install pillow and wxpy 模块
3.开始:
1 from wxpy import * 2 import PIL.Image as Image 3 import os 4 import sys 5 #登陆微信 6 bot = Bot(console_qr=2,cache_path="botoo.pkl") 7 #获取当前路径 8 curr_dir = os.path.abspath(sys.argv[0]) 9 #创建文件夹,用来放照片10 if not os.path.exists(curr_dir + "FriendImages/"):11os.mkdir(curr_dir + "FriendImages/")12 #获取朋友的头像13 my_friends = bot.friends(update=True)14 n = 0 15 for friend in my_friends:16friend.get_avatar(curr_dir + "FriendImages/" + str(n) + ".jpg")17n = n+118 #首先设定照片墙的大小,尺寸(650*650)19 image = Image.new("RGB",(850,850))20 x = 0 21 y = 022 #获取之前放照片的位置23 curr_dir = os.path.abspath(sys.argv[0])24 #逐个获取照片25 ls = os.listdir(curr_dir + "FriendImages")26 for file_names in ls:27try:28 img = Image.open(curr_dir + "FriendImages/" + file_names)29except IOError:30 continue31else:32 #设定好友头像的大小,为50*5033 img = img.resize((50,50),Image.ANTIALIAS)34 image.paste(img,(x*50,y*50))35 x += 136 if x ==17:37 x = 038 y += 139 img = image.save(curr_dir + "wechat_friend_wall.jpg")40 #最终生成17*17个头像的一个照片墙