python--制作微信好友照片墙
知识来源: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个头像的一个照片墙
每天进步一点点~~
分类:
python
标签:
python 小案子
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!