-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.py
39 lines (36 loc) · 1.02 KB
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import itchat
import math
import PIL.Image as Image
import os
itchat.auto_login()
friends = itchat.get_friends(update=True)[0:]
user = friends[0]["UserName"]
num = 0
for i in friends:
img = itchat.get_head_img(userName=i["UserName"])
fileImage = open('./saveImg' + "/" + str(num) + ".jpg",'wb')
fileImage.write(img)
fileImage.close()
num += 1
ls = os.listdir('./saveImg')
each_size = int(math.sqrt(float(640*640)/len(ls)))
lines = int(640/each_size)
image = Image.new('RGB', (640, 640))
x = 0
y = 0
for i in range(0,len(ls)+1):
try:
img = Image.open('./saveImg' + "/" + str(i) + ".jpg")
if img.mode != "RGB":
img = img.convert("RGB")
except IOError:
print("Error")
else:
img = img.resize((each_size, each_size), Image.ANTIALIAS)
image.paste(img, (x * each_size, y * each_size))
x += 1
if x == lines:
x = 0
y += 1
image.save('./saveImg' + "/" + "all.jpg")
itchat.send_image('./saveImg' + "/" + "all.jpg", 'filehelper')