日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python3 生成微信好友头像的图片合集

發布時間:2024/3/24 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python3 生成微信好友头像的图片合集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

剛才在github上看到一個大神寫的生成微信好友圖像集合的腳本
自己運行了一下發現挺好玩的

原帖地址:https://github.com/aloneZERO/py-party/tree/master/wechat-imgs #!python3 # coding: utf-8import itchat import osfrom PIL import Image import math# 首先登陸python版本微信itchat,生成二維碼 # itchat.auto_login(enableCmdQR=True) itchat.auto_login()# 獲取好友列表 friends = itchat.get_friends(update=True)[0:]# 以自己的用戶名加密碼創建文件夾來存儲圖片 user = friends[0]["UserName"] print("User Code: "+user) os.mkdir(user)# 使用itchat的get_head_img(userName=none)函數 # 爬取好友列表的頭像,并下載到本地 num = 0 for i in friends:img = itchat.get_head_img(userName=i["UserName"])with open(user + "/" + str(num) + ".jpg", 'wb') as fileImage:fileImage.write(img)num += 1# 計算好友數量 pics = os.listdir(user) numPic = len(pics) print("好友總數:"+str(numPic))# 計算每張頭像縮小后的邊長(默認為正方形) eachsize = int(math.sqrt(float(640 * 640) / numPic)) # print(eachsize)# 計算合成圖片每一邊分為多少小邊 numline = int(640 / eachsize) toImage = Image.new('RGBA', (640, 640)) # print(numline)# 縮小并拼接圖片 x, y = 0, 0 for i in pics:try:# 打開圖片img = Image.open(user + "/" + i)except IOError:print("Error: 沒有找到文件或讀取文件失敗")else:# 縮小圖片img = img.resize((eachsize, eachsize), Image.ANTIALIAS)# 拼接圖片toImage.paste(img, (x * eachsize, y * eachsize))x += 1if x == numline:x = 0y += 1# 保存拼接好的圖片 # 通過文件助手發送給自己 toImage.save("funny.jpg") itchat.send_image("funny.jpg", 'filehelper') print("好友頭像拼接完畢,快去查看吧~")

轉載于:https://www.cnblogs.com/xuyuQAQ/p/8426021.html

總結

以上是生活随笔為你收集整理的Python3 生成微信好友头像的图片合集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。