-
Notifications
You must be signed in to change notification settings - Fork 56
/
wxImage.py
69 lines (44 loc) · 1.11 KB
/
wxImage.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import itchat
import os
import PIL.Image as Image
from os import listdir
import math
itchat.auto_login(enableCmdQR=True)
friends = itchat.get_friends(update=True)[0:]
user = friends[0]["UserName"]
print(user)
os.mkdir(user)
num = 0
for i in friends:
img = itchat.get_head_img(userName=i["UserName"])
fileImage = open(user + "/" + str(num) + ".jpg",'wb')
fileImage.write(img)
fileImage.close()
num += 1
pics = listdir(user)
numPic = len(pics)
print(numPic)
eachsize = int(math.sqrt(float(640 * 640) / numPic))
print(eachsize)
numline = int(640 / eachsize)
toImage = Image.new('RGBA', (640, 640))
print(numline)
x = 0
y = 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 += 1
if x == numline:
x = 0
y += 1
toImage.save(user + ".jpg")
itchat.send_image(user + ".jpg", 'filehelper')