Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import itchat
  2. import os
  3. import math
  4. from PIL import Image
  5.  
  6. itchat.auto_login(hotReload=True) # 扫码登录微信
  7.  
  8. if not os.path.exists('img'): # 如果同目录没有img目录
  9. os.mkdir('img') # 创建img目录
  10.  
  11. """
  12. friends = itchat.get_friends() # 得到好友列表
  13. num = 0
  14.  
  15. for friend in friends:
  16. img = itchat.get_head_img(userName=friend['UserName']) # 得到每个好友头像
  17. with open('img/' + str(num) + '.png', 'wb') as f: # 按数字顺序在img目录存好友头像
  18. f.write(img)
  19. num += 1
  20.  
  21. """
  22. images = os.listdir('img')
  23. each_size = int(math.sqrt((640 * 640) / len(images))) # 定义好友头像像素
  24. line = int(640 / each_size) # 定义一个新图片中头像行数
  25. image = Image.new('RGBA', (640, 640)) # 定义一个640*640新图片
  26.  
  27. x = 0
  28. y = 0
  29. for i in images:
  30. img = Image.open('img/' + i)
  31. img1 = img.resize((each_size, each_size), Image.ANTIALIAS) # 缩放好友头像
  32. image.paste(img1, (x * each_size, y * each_size))
  33. x += 1
  34. if x == line:
  35. x = 0
  36. y += 1
  37.  
  38. image.save('img/all.png') # 将缩放后的好友头像粘到640*640的新图片中
  39. print('Done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement