python--制作微信好友照片墙
时间:2019-08-19 23:07:48
收藏:0
阅读:228
知识来源:https://zhuanlan.zhihu.com/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/"): 11 os.mkdir(curr_dir + "FriendImages/") 12 #获取朋友的头像 13 my_friends = bot.friends(update=True) 14 n = 0 15 for friend in my_friends: 16 friend.get_avatar(curr_dir + "FriendImages/" + str(n) + ".jpg") 17 n = n+1 18 #首先设定照片墙的大小,尺寸(650*650) 19 image = Image.new("RGB",(850,850)) 20 x = 0 21 y = 0 22 #获取之前放照片的位置 23 curr_dir = os.path.abspath(sys.argv[0]) 24 #逐个获取照片 25 ls = os.listdir(curr_dir + "FriendImages") 26 for file_names in ls: 27 try: 28 img = Image.open(curr_dir + "FriendImages/" + file_names) 29 except IOError: 30 continue 31 else: 32 #设定好友头像的大小,为50*50 33 img = img.resize((50,50),Image.ANTIALIAS) 34 image.paste(img,(x*50,y*50)) 35 x += 1 36 if x ==17: 37 x = 0 38 y += 1 39 img = image.save(curr_dir + "wechat_friend_wall.jpg") 40 #最终生成17*17个头像的一个照片墙
评论(0)