-
Notifications
You must be signed in to change notification settings - Fork 5
/
icongen.sh
executable file
·330 lines (267 loc) · 8.63 KB
/
icongen.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
#!/usr/bin/env bash
#---------------------------
# This script assumes that ImageMagick is installed with Ghostscript
# and the convert command is accessible via the $PATH variable
#
# If not, these should be easily installed with:
# brew install imagemagick
# brew install ghostscript
#---------------------------
#---------------------------
#***************************
# App Specific Configuration
#***************************
#---------------------------
buildNumberTextColor="black"
environmentTextColor="white"
splashSizePercentageAsDecimal=0.7
#---------------------------
#***************************
# End App Specific Configuration
#***************************
#---------------------------
#---------------------------
# Get Arguments
#---------------------------
EXPECTED_ARGS=2
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: ./icongen.sh [app name] [platform] [environment (optional)] [buildString (optional)]"
echo "ex: ./icongen.sh app ios production \"1.2.4\""
exit 1
fi
appName="app"
platform="web"
env=""
buildString=""
if [ "$1" ]
then
appName=$1
fi
if [ "$2" ]
then
platform=$2
fi
if [ "$3" ]
then
env=$3
fi
if [ "$4" ]
then
buildString=$4
fi
#format
if [ "$env" == "prod" -o "$env" == "production" ]
then
env="PROD"
fi
if [ "$env" == "stage" -o "$env" == "staging" ]
then
env="STAGE"
fi
if [ "$env" == "local" ]
then
env="LOCAL"
fi
#---------------------------
# Set Variables
#---------------------------
path="_icon_source.png"
splashPath="_splash_source.png"
banner="_banner_source.png"
tmp="tmp.png"
rootWebPath="src/www"
webPath="${rootWebPath}/assets/img"
iosPath="cordova/platforms/ios/${appName}/Resources/icons"
iosSplashPath="cordova/platforms/ios/${appName}/Resources/splash"
androidPath="cordova/platforms/android/res"
iconFillColor=$(convert $path -format "%[pixel: u.p{0,0}]" info:)
splashFillColor=$(convert $splashPath -format "%[pixel: u.p{0,0}]" info:)
set -x
set -e
#---------------------------
# Build Platform Specific
#---------------------------
font1="Helvetica"
font2="Helvetica-Bold"
buildOS="unknown"
unamestr=`uname`
if [[ "$unamestr" == "Linux" ]]
then
buildOS="linux"
font1="DejaVu-Sans"
font2="DejaVu-Sans-Bold"
elif [[ "$unamestr" == "Darwin" ]]
then
buildOS="osx"
fi
#---------------------------
# Create labeled icon
#---------------------------
if [ "$buildString" != "" ]
then
composite ${banner} ${path} ${tmp}
convert ${tmp} \
-fill ${buildNumberTextColor} \
-font ${font1} \
-gravity north \
-pointsize 100 \
-annotate +0+50 ${buildString} \
${tmp}
convert ${tmp} \
-gravity center \
-rotate 45 \
${tmp}
convert ${tmp} \
-fill ${environmentTextColor} \
-font ${font2} \
-pointsize 130 \
-gravity south \
-annotate -220+10 ${env} \
${tmp}
convert ${tmp} \
-gravity center \
-rotate -45 \
${tmp}
convert ${tmp} -crop 1024x1024+0+0 +repage ${tmp}
path=${tmp}
fi
# This function takes in the dimension of the icon
# (it assumes the icon is a square) and the name of the file to save the icon to.
function createIconImage()
{
iconDimension=$1
fileName=$2
convert ${path} \
-resize ${iconDimension}x${iconDimension}^ \
-gravity center \
-extent ${iconDimension}x${iconDimension} \
-unsharp 0x1 \
${fileName}
}
# This function takes in the dimension of the splash screen
# and scales the source image to fit well in the layout
function createSplashImage()
{
width=$1
height=$2
fileName=$3
innerDimension=$(echo "$splashSizePercentageAsDecimal*$width" | bc)
if [ "$width" -gt "$height" ]
then
innerDimension=$(echo "$splashSizePercentageAsDecimal*$height" | bc)
fi
convert ${splashPath} \
-background ${splashFillColor} \
-resize ${innerDimension}x${innerDimension}^ \
-gravity center \
-extent ${width}x${height} \
-unsharp 0x1 \
${fileName}
}
#---------------------------
# Do web specific things
#---------------------------
if [ "$platform" == "web" ]
then
createIconImage 57 ${webPath}/apple-icon-57x57.png
createIconImage 60 ${webPath}/apple-icon-60x60.png
createIconImage 72 ${webPath}/apple-icon-72x72.png
createIconImage 76 ${webPath}/apple-icon-76x76.png
createIconImage 114 ${webPath}/apple-icon-114x114.png
createIconImage 120 ${webPath}/apple-icon-120x120.png
createIconImage 144 ${webPath}/apple-icon-144x144.png
createIconImage 152 ${webPath}/apple-icon-152x152.png
createIconImage 180 ${webPath}/apple-icon-180x180.png
createIconImage 192 ${webPath}/android-icon-192x192.png
createIconImage 32 ${webPath}/favicon-32x32.png
createIconImage 96 ${webPath}/favicon-96x96.png
createIconImage 16 ${webPath}/favicon-16x16.png
createIconImage 36 ${webPath}/android-icon-36x36.png
createIconImage 48 ${webPath}/android-icon-48x48.png
createIconImage 72 ${webPath}/android-icon-72x72.png
createIconImage 96 ${webPath}/android-icon-96x96.png
createIconImage 144 ${webPath}/android-icon-144x144.png
createIconImage 192 ${webPath}/android-icon-192x192.png
createIconImage 558 ${webPath}/tile.png
# Create Tile Wide
convert "$path" \
-background ${iconFillColor} \
-resize 270x270^ \
-gravity center \
-extent 558x270 \
${webPath}/tile-wide.png
# Create favicon.ico
convert "$path" -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
-delete 0 -alpha off -colors 256 ${rootWebPath}/favicon.ico
createSplashImage 320 460 ${webPath}/splash-320x460.png
createSplashImage 320 480 ${webPath}/splash-320x480.png
createSplashImage 640 920 ${webPath}/splash-640x920.png
createSplashImage 640 960 ${webPath}/splash-640x960.png
createSplashImage 640 1096 ${webPath}/splash-640x1096.png
createSplashImage 640 1136 ${webPath}/splash-640x1136.png
createSplashImage 768 1004 ${webPath}/splash-768x1004.png
createSplashImage 1024 748 ${webPath}/splash-1024x748.png
createSplashImage 1536 2008 ${webPath}/splash-1536x2008.png
createSplashImage 2048 1496 ${webPath}/splash-2048x1496.png
fi
#---------------------------
# Do iOS specific things
#---------------------------
if [ "$platform" == "ios" ]
then
createIconImage 40 ${iosPath}/icon-40.png
createIconImage 80 ${iosPath}/[email protected]
createIconImage 50 ${iosPath}/icon-50.png
createIconImage 100 ${iosPath}/[email protected]
createIconImage 60 ${iosPath}/icon-60.png
createIconImage 120 ${iosPath}/[email protected]
createIconImage 180 ${iosPath}/[email protected]
createIconImage 72 ${iosPath}/icon-72.png
createIconImage 144 ${iosPath}/[email protected]
createIconImage 76 ${iosPath}/icon-76.png
createIconImage 152 ${iosPath}/[email protected]
createIconImage 29 ${iosPath}/icon-small.png
createIconImage 58 ${iosPath}/[email protected]
createIconImage 57 ${iosPath}/icon.png
createIconImage 114 ${iosPath}/[email protected]
createSplashImage 640 1136 ${iosSplashPath}/Default-568h@2x~iphone.png
createSplashImage 750 1334 ${iosSplashPath}/Default-667h.png
createSplashImage 1242 2208 ${iosSplashPath}/Default-736h.png
createSplashImage 2208 1242 ${iosSplashPath}/Default-Landscape-736h.png
createSplashImage 2048 1536 ${iosSplashPath}/Default-Landscape@2x~ipad.png
createSplashImage 1024 768 ${iosSplashPath}/Default-Landscape~ipad.png
createSplashImage 1536 2048 ${iosSplashPath}/Default-Portrait@2x~ipad.png
createSplashImage 768 1024 ${iosSplashPath}/Default-Portrait~ipad.png
createSplashImage 640 960 ${iosSplashPath}/Default@2x~iphone.png
createSplashImage 320 480 ${iosSplashPath}/Default~iphone.png
fi
#---------------------------
# Do android specific things
#---------------------------
if [ "$platform" == "android" ]
then
createIconImage 72 ${androidPath}/drawable-hdpi/icon.png
createIconImage 36 ${androidPath}/drawable-ldpi/icon.png
createIconImage 48 ${androidPath}/drawable-mdpi/icon.png
createIconImage 96 ${androidPath}/drawable-xhdpi/icon.png
createSplashImage 800 480 ${androidPath}/drawable-land-hdpi/screen.png
createSplashImage 320 200 ${androidPath}/drawable-land-ldpi/screen.png
createSplashImage 480 320 ${androidPath}/drawable-land-mdpi/screen.png
createSplashImage 1280 720 ${androidPath}/drawable-land-xhdpi/screen.png
createSplashImage 480 800 ${androidPath}/drawable-port-hdpi/screen.png
createSplashImage 200 320 ${androidPath}/drawable-port-ldpi/screen.png
createSplashImage 320 480 ${androidPath}/drawable-port-mdpi/screen.png
createSplashImage 720 1280 ${androidPath}/drawable-port-xhdpi/screen.png
fi
#---------------------------
# Remove temp file
#---------------------------
if [ -e "${tmp}" ]
then
rm ${tmp}
fi