forked from smallmuou/ios-icon-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ios-icon-generator.sh
executable file
·455 lines (392 loc) · 13.8 KB
/
ios-icon-generator.sh
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
#!/bin/bash
#
# Copyright (C) 2014 Wenva <lvyexuwenfa100@126.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
set -e
SRC_FILE="$1"
DST_PATH="$2"
BGCOLOR="white"
VERSION=1.0.0
info() {
local green="\033[1;32m"
local normal="\033[0m"
echo -e "[${green}INFO${normal}] $1"
}
error() {
local red="\033[1;31m"
local normal="\033[0m"
echo -e "[${red}ERROR${normal}] $1"
}
usage() {
cat << EOF
VERSION: $VERSION
USAGE:
$0 srcfile dstpath
DESCRIPTION:
This script aim to generate ios app icons easier and simply.
srcfile - The source png image. Preferably above 1024x1024
dstpath - The destination path where the icons generate to.
This script is depend on ImageMagick. So you must install ImageMagick first
You can use 'sudo brew install ImageMagick' to install it
AUTHOR:
Pawpaw<lvyexuwenfa100@126.com>
LICENSE:
This script follow MIT license.
EXAMPLE:
$0 1024.png ~/123
EOF
}
# Check ImageMagick
command -v convert >/dev/null 2>&1 || { error >&2 "The ImageMagick is not installed. Please use brew to install it first."; exit -1; }
# Check param
if [ $# != 2 ];then
usage
exit -1
fi
# Check dst path whether exist.
if [ ! -d "$DST_PATH" ];then
mkdir -p "$DST_PATH"
fi
# Generate, refer to:https://developer.apple.com/ios/human-interface-guidelines/graphics/app-icon/
# Device or context Icon size
## iPhone 6s Plus, iPhone 6 Plus 180px by 180px
## iPhone 6s, iPhone 6, iPhone SE 120px by 120px
## iPad Pro 167px by 167px
## iPad, iPad mini 152px by 152px
## App Store 1024px by 1024px
# Device Spotlight icon size Settings icon size
# iPhone 6s Plus, iPhone 6 Plus 120px by 120px 87px by 87px
# iPhone 6s, iPhone 6, iPhone SE 80px by 80px 58px by 58px
# iPad Pro, iPad, iPad mini 80px by 80px 58px by 58px
info 'App Store Icon...'
convert "$SRC_FILE" -resize 1024X1024 "$DST_PATH/iTunesArtwork@2x.png"
info 'Generating:'
if [ ! -d "$DST_PATH/android" ];then
mkdir -p "$DST_PATH/android/"
fi
if [ ! -d "$DST_PATH/android/icons" ];then
mkdir -p "$DST_PATH/android/icons/"
fi
if [ ! -d "$DST_PATH/android/icons/mipmap-mdpi" ];then
mkdir -p "$DST_PATH/android/icons/mipmap-mdpi"
fi
if [ ! -d "$DST_PATH/android/icons/mipmap-hdpi" ];then
mkdir -p "$DST_PATH/android/icons/mipmap-hdpi"
fi
if [ ! -d "$DST_PATH/android/icons/mipmap-xhdpi" ];then
mkdir -p "$DST_PATH/android/icons/mipmap-xhdpi"
fi
if [ ! -d "$DST_PATH/android/icons/mipmap-xxhdpi" ];then
mkdir -p "$DST_PATH/android/icons/mipmap-xxhdpi"
fi
if [ ! -d "$DST_PATH/android/icons/mipmap-xxxhdpi" ];then
mkdir -p "$DST_PATH/android/icons/mipmap-xxxhdpi"
fi
info 'android_mdpi icon...'
convert "$SRC_FILE" -resize 48x48 "$DST_PATH/android/icons/mipmap-mdpi/ic_launcher.png"
info 'android_hdpi icon...'
convert "$SRC_FILE" -resize 72x72 "$DST_PATH/android/icons/mipmap-hdpi/ic_launcher.png"
info 'android_xhdpi icon...'
convert "$SRC_FILE" -resize 96x96 "$DST_PATH/android/icons/mipmap-xhdpi/ic_launcher.png"
info 'android_xxhdpi icon...'
convert "$SRC_FILE" -resize 144x144 "$DST_PATH/android/icons/mipmap-xxhdpi/ic_launcher.png"
info 'android_xxxhdpi icon...'
convert "$SRC_FILE" -resize 192x192 "$DST_PATH/android/icons/mipmap-xxxhdpi/ic_launcher.png"
# Check dst path whether exist.
if [ ! -d "$DST_PATH/AppIcon.appiconset" ];then
mkdir -p "$DST_PATH/AppIcon.appiconset/"
fi
info 'iPhone Notification Icon...'
convert "$SRC_FILE" -resize 40x40 "$DST_PATH/AppIcon.appiconset/icon-20@2x.png"
convert "$SRC_FILE" -resize 60x60 "$DST_PATH/AppIcon.appiconset/icon-20@3x.png"
info 'iPhone Settings Icon...'
convert "$SRC_FILE" -resize 58x58 "$DST_PATH/AppIcon.appiconset/icon-small@2x.png"
convert "$SRC_FILE" -resize 87x87 "$DST_PATH/AppIcon.appiconset/icon-small@3x.png"
info 'iPhone Spotlight Icon...'
convert "$SRC_FILE" -resize 80x80 "$DST_PATH/AppIcon.appiconset/icon-40@2x.png"
convert "$SRC_FILE" -resize 120x120 "$DST_PATH/AppIcon.appiconset/icon-40@3x.png"
info 'iPhone App Icon...'
convert "$SRC_FILE" -resize 120x120 "$DST_PATH/AppIcon.appiconset/icon-60@2x.png"
convert "$SRC_FILE" -resize 180x180 "$DST_PATH/AppIcon.appiconset/icon-60@3x.png"
info 'iPad Notifications Icon...'
convert "$SRC_FILE" -resize 20x20 "$DST_PATH/AppIcon.appiconset/icon-20.png"
info 'iPad Settings Icon...'
convert "$SRC_FILE" -resize 29x29 "$DST_PATH/AppIcon.appiconset/icon-small.png"
info 'iPad Spotlight Icon...'
convert "$SRC_FILE" -resize 80x80 "$DST_PATH/AppIcon.appiconset/icon-40.png"
info 'iPad App Icon...'
convert "$SRC_FILE" -resize 76x76 "$DST_PATH/AppIcon.appiconset/icon-76.png"
convert "$SRC_FILE" -resize 152x152 "$DST_PATH/AppIcon.appiconset/icon-76@2x.png"
info 'iPad Pro Icon...'
convert "$SRC_FILE" -resize 167x167 "$DST_PATH/AppIcon.appiconset/icon-83.5@2x.png"
info 'App Store Icon...'
convert "$SRC_FILE" -resize 1024x1024 "$DST_PATH/AppIcon.appiconset/AppStore.png"
cat <<EOF > $DST_PATH/AppIcon.appiconset/Contents.json
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "icon-20@2x.png",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "icon-20@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "icon-small@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "icon-small@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "icon-40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "icon-40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "icon-60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "icon-60@3x.png",
"scale" : "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "icon-20.png",
"scale" : "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "icon-20@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "icon-small.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "icon-small@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "icon-40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "icon-40@2x.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "icon-76.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "icon-76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "icon-83.5@2x.png",
"scale" : "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "AppStore.png",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
EOF
# Check dst path whether exist.
if [ ! -d "$DST_PATH/LaunchImage.launchimage" ];then
mkdir -p "$DST_PATH/LaunchImage.launchimage/"
fi
info 'Generating extended Default image'
#convert "$SRC_FILE" -background white -gravity center -extent 200% "$SRC_FILE.extended"
SRC_FILE="$SRC_FILE"
info "$SRC_FILE"
info 'Generating Launch Screen set...'
info 'iPhone pre 5 Portrait (640x960)...'
convert "$SRC_FILE" -thumbnail 640x960 -background $BGCOLOR -gravity center -extent 640x960 "$DST_PATH/LaunchImage.launchimage/Default@2x~iphone.png"
info 'iPhone 5 Portrait (640x1136)...'
convert "$SRC_FILE" -thumbnail 640x1136 -background $BGCOLOR -gravity center -extent 640x1136 "$DST_PATH/LaunchImage.launchimage/Default-568h@2x~iphone.png"
info 'iPhone 6 Portrait (750x1334)...'
convert "$SRC_FILE" -thumbnail 750x1334 -background $BGCOLOR -gravity center -extent 750x1334 "$DST_PATH/LaunchImage.launchimage/Default-667h.png"
info 'iPhone 6 Portrait (1242x2208)...'
convert "$SRC_FILE" -thumbnail 1242x2208 -background $BGCOLOR -gravity center -extent 1242x2208 "$DST_PATH/LaunchImage.launchimage/Default-736h.png"
info 'iPhone 6 Portrait (2208x1242)...'
convert "$SRC_FILE" -thumbnail 2208x1242 -background $BGCOLOR -gravity center -extent 2208x1242 "$DST_PATH/LaunchImage.launchimage/Default-Landscape-736h.png"
info 'iPad Portrait (768x1024)...'
convert "$SRC_FILE" -thumbnail 768x1024 -background $BGCOLOR -gravity center -extent 768x1024 "$DST_PATH/LaunchImage.launchimage/Default-Portrait~ipad.png"
info 'iPad Landscape (1024x768)...'
convert "$SRC_FILE" -thumbnail 1024x768 -background $BGCOLOR -gravity center -extent 1024x768 "$DST_PATH/LaunchImage.launchimage/Default-Landscape~ipad.png"
info 'iPad Portrait @2x (1536x2048)...'
convert "$SRC_FILE" -thumbnail 1536x2048 -background $BGCOLOR -gravity center -extent 1536x2048 "$DST_PATH/LaunchImage.launchimage/Default-Portrait@2x~ipad.png"
info 'iPad Landscape @2x (2048x1536)...'
convert "$SRC_FILE" -thumbnail 2048x1536 -background $BGCOLOR -gravity center -extent 2048x1536 "$DST_PATH/LaunchImage.launchimage/Default-Landscape@2x~ipad.png"
info 'Contents.json...'
cat <<EOF > $DST_PATH/LaunchImage.launchimage/Contents.json
{
"images" : [
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "736h",
"filename" : "Default-736h.png",
"minimum-system-version" : "8.0",
"orientation" : "portrait",
"scale" : "3x"
},
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "736h",
"filename" : "Default-Landscape-736h.png",
"minimum-system-version" : "8.0",
"orientation" : "landscape",
"scale" : "3x"
},
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "667h",
"filename" : "Default-667h.png",
"minimum-system-version" : "8.0",
"orientation" : "portrait",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"filename" : "Default@2x~iphone.png",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "retina4",
"filename" : "Default-568h@2x~iphone.png",
"minimum-system-version" : "7.0",
"orientation" : "portrait",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"filename" : "Default-Portrait~ipad.png",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"filename" : "Default-Landscape~ipad.png",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"filename" : "Default-Portrait@2x~ipad.png",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"filename" : "Default-Landscape@2x~ipad.png",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
EOF
if [ ! -d "$DST_PATH/android/splashes" ];then
mkdir -p "$DST_PATH/android/splashes/"
fi
info 'android_mdpi_portrait...'
convert "$SRC_FILE" -thumbnail 320x480 -background $BGCOLOR -gravity center -extent 320x480 "$DST_PATH/android/splashes/android_mdpi_portrait.png"
info 'android_mdpi_landscape...'
convert "$SRC_FILE" -thumbnail 480x320 -background $BGCOLOR -gravity center -extent 480x320 "$DST_PATH/android/splashes/android_mdpi_landscape.png"
info 'android_hdpi_portrait...'
convert "$SRC_FILE" -thumbnail 480x800 -background $BGCOLOR -gravity center -extent 480x800 "$DST_PATH/android/splashes/android_hdpi_portrait.png"
info 'android_hdpi_landscape...'
convert "$SRC_FILE" -thumbnail 800x480 -background $BGCOLOR -gravity center -extent 800x480 "$DST_PATH/android/splashes/android_hdpi_landscape.png"
info 'android_xhdpi_portrait...'
convert "$SRC_FILE" -thumbnail 720x1280 -background $BGCOLOR -gravity center -extent 720x1280 "$DST_PATH/android/splashes/android_xhdpi_portrait.png"
info 'android_xhdpi_landscape...'
convert "$SRC_FILE" -thumbnail 1280x720 -background $BGCOLOR -gravity center -extent 1280x720 "$DST_PATH/android/splashes/android_xhdpi_landscape.png"
info 'android_xxhdpi_portrait...'
convert "$SRC_FILE" -thumbnail 1080x1440 -background $BGCOLOR -gravity center -extent 1080x1440 "$DST_PATH/android/splashes/android_xxhdpi_portrait.png"
info 'android_xxhdpi_landscape...'
convert "$SRC_FILE" -thumbnail 1440x1080 -background $BGCOLOR -gravity center -extent 1440x1080 "$DST_PATH/android/splashes/android_xxhdpi_landscape.png"
info 'Generate Done.'