-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathautoExportAppIcon.py
208 lines (190 loc) · 5.22 KB
/
autoExportAppIcon.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python
# coding: utf-8
# 简介: iOS app图标生成脚本, 生成后直接拖入xcode中就行
# 用法: python autoExportAppIcon.py /path/xxx.png
import sys
import os
try:
from PIL import Image
except:
print ('\033[31m' + '缺少Image模块,正在安装Image模块,请等待...' + '\033[0m')
success = os.system('python -m pip install Image')
if success == 0:
print('\033[7;32m' + 'Image模块安装成功.' + '\033[0m')
from PIL import Image
else:
print ('\033[31m' + 'Image安装失败,请手动在终端执行:\'python -m pip install Image\'重新安装.' + '\033[0m')
quit()
outPutPath = os.path.expanduser('~') + '/Desktop/AppIcon/'
if not os.path.exists(outPutPath):
os.mkdir(outPutPath)
if len(sys.argv) <= 1:
print ('\033[31m' + '请输入图片路径,eg: python autoExportAppIcon.py /path/xxx.png' + '\033[0m')
quit()
ImageName = sys.argv[1]
# print('图片名字为:' + ImageName)
originImg = ''
try:
originImg = Image.open(ImageName)
except:
print ('\033[31m' + '\'' + ImageName + '\'' + ',该文件不是图片文件,请检查文件路径.' + '\033[0m')
quit()
# 20x20
img0 = originImg.resize((20,20), Image.ANTIALIAS)
img1 = originImg.resize((40,40), Image.ANTIALIAS)
img2 = originImg.resize((60,60), Image.ANTIALIAS)
img0.save(outPutPath + 'AppIcon20x20.png',"png")
img1.save(outPutPath + '[email protected]',"png")
img2.save(outPutPath + '[email protected]',"png")
# 29x29
img3 = originImg.resize((29,29), Image.ANTIALIAS)
img4 = originImg.resize((58,58), Image.ANTIALIAS)
img5 = originImg.resize((87,87), Image.ANTIALIAS)
img3.save(outPutPath + 'AppIcon29x29.png',"png")
img4.save(outPutPath + '[email protected]',"png")
img5.save(outPutPath + '[email protected]',"png")
# 40x40
img6 = originImg.resize((40,40), Image.ANTIALIAS)
img7 = originImg.resize((80,80), Image.ANTIALIAS)
img8 = originImg.resize((120,120), Image.ANTIALIAS)
img6.save(outPutPath + 'AppIcon40x40.png',"png")
img7.save(outPutPath + '[email protected]',"png")
img8.save(outPutPath + '[email protected]',"png")
# 60x60
img9 = originImg.resize((120,120), Image.ANTIALIAS)
img10 = originImg.resize((180,180), Image.ANTIALIAS)
img9.save(outPutPath + '[email protected]',"png")
img10.save(outPutPath + '[email protected]',"png")
# ipad
img11 = originImg.resize((76,76), Image.ANTIALIAS)
img12 = originImg.resize((152,152), Image.ANTIALIAS)
img13 = originImg.resize((167,167), Image.ANTIALIAS)
img11.save(outPutPath + 'AppIcon76x76.png',"png")
img12.save(outPutPath + '[email protected]',"png")
img13.save(outPutPath + '[email protected]',"png")
# 1024x1024 xcode10
img14 = originImg.resize((1024,1024), Image.ANTIALIAS)
img14.save(outPutPath + 'AppIcon1024x1024.png',"png")
# 创建Contents.json文件
content = '''
{
"images" : [
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"filename" : "[email protected]",
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"filename" : "AppIcon20x20.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"filename" : "AppIcon29x29.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"filename" : "AppIcon40x40.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"filename" : "AppIcon76x76.png",
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"filename" : "[email protected]",
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"filename" : "AppIcon1024x1024.png",
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
'''
f = open(outPutPath + 'Contents.json', 'w')
f.write(content)
print('\033[7;32m' + '文件输出文件夹:' + outPutPath + '\033[0m')
os.system('open ' + outPutPath)