Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itchat
- import os
- import math
- from PIL import Image
- itchat.auto_login(hotReload=True) # 扫码登录微信
- if not os.path.exists('img'): # 如果同目录没有img目录
- os.mkdir('img') # 创建img目录
- """
- friends = itchat.get_friends() # 得到好友列表
- num = 0
- for friend in friends:
- img = itchat.get_head_img(userName=friend['UserName']) # 得到每个好友头像
- with open('img/' + str(num) + '.png', 'wb') as f: # 按数字顺序在img目录存好友头像
- f.write(img)
- num += 1
- """
- images = os.listdir('img')
- each_size = int(math.sqrt((640 * 640) / len(images))) # 定义好友头像像素
- line = int(640 / each_size) # 定义一个新图片中头像行数
- image = Image.new('RGBA', (640, 640)) # 定义一个640*640新图片
- x = 0
- y = 0
- for i in images:
- img = Image.open('img/' + i)
- img1 = img.resize((each_size, each_size), Image.ANTIALIAS) # 缩放好友头像
- image.paste(img1, (x * each_size, y * each_size))
- x += 1
- if x == line:
- x = 0
- y += 1
- image.save('img/all.png') # 将缩放后的好友头像粘到640*640的新图片中
- print('Done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement