python--制作微信好友照片墙
2024-09-07 11:30:12
知识来源:https://zhuanlan.zhihu.com/p/73975013
1.环境
os:MAC
tool:python 3.7 ,pip3.7
2.前提:
使用pip3.7 install pillow and wxpy 模块
3.开始:
from wxpy import *
import PIL.Image as Image
import os
import sys
#登陆微信
bot = Bot(console_qr=2,cache_path="botoo.pkl")
#获取当前路径
curr_dir = os.path.abspath(sys.argv[0])
#创建文件夹,用来放照片
if not os.path.exists(curr_dir + "FriendImages/"):
os.mkdir(curr_dir + "FriendImages/")
#获取朋友的头像
my_friends = bot.friends(update=True)
n = 0
for friend in my_friends:
friend.get_avatar(curr_dir + "FriendImages/" + str(n) + ".jpg")
n = n+1
#首先设定照片墙的大小,尺寸(650*650)
image = Image.new("RGB",(850,850))
x = 0
y = 0
#获取之前放照片的位置
curr_dir = os.path.abspath(sys.argv[0])
#逐个获取照片
ls = os.listdir(curr_dir + "FriendImages")
for file_names in ls:
try:
img = Image.open(curr_dir + "FriendImages/" + file_names)
except IOError:
continue
else:
#设定好友头像的大小,为50*50
img = img.resize((50,50),Image.ANTIALIAS)
image.paste(img,(x*50,y*50))
x += 1
if x ==17:
x = 0
y += 1
img = image.save(curr_dir + "wechat_friend_wall.jpg")
#最终生成17*17个头像的一个照片墙
最新文章
- tomcat 假死现象(转)
- 学习Coding-iOS开源项目日志(一)
- C代码中如何调用C++ C++中如何调用C
- txt用Itunes同步到IPhone上
- C# DateTime和DateTime?格式化时间
- How to Make LastPass Even More Secure with Google Authenticator
- UPC 2959: Caoshen like math 这就是个水题
- Android使用OpenGL ES2.0显示YUV,您的手机上的数据要解决两个方面的坐标
- C语言 - 预编译
- DynamicXml
- 推荐一款接口文档在线管理系统-MinDoc
- IDEA编写css样式报错
- css解决内联元素间的空白间隔
- C#File类常用文件操作以及一个模拟的控制台文件管理系统
- Kotlin Native
- makefile编写规则
- 腾讯 xtestserver 基本使用教程~
- HDU 2012 素数判定
- OneNET麒麟座应用开发之十:空气质量数据监测站项目总结
- sklearn linear_model,svm,tree,naive bayes,ensemble
热门文章
- pytorch 中LSTM模型获取最后一层的输出结果,单向或双向
- 使用 Junit + Mockito 实践单元测试
- Jenkins(3)- 安装Jenkins过程中遇到问题的排查思路
- ISO及安全业务,机制
- MySql -- 数据结构
- Spring框架中文件目录遍历漏洞 Directory traversal in Spring framework
- hexo-themes-setting
- 【高并发】由InterruptedException异常引发的思考
- HR问了我朋友什么是简单工厂模式,竟被质疑是否学过设计模式,是否是计算机专业?
- Codeforce-Ozon Tech Challenge 2020-A. Kuroni and the Gifts