-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate.sh
executable file
·195 lines (152 loc) · 6.99 KB
/
generate.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
#!/bin/bash
# Uses imagemagick
# brew install imagemagick
# Usage
# -------------------------------------------
# Example: `generate.sh icon.png launch.png "#ff0000" src`
usage() { echo "usage: $0 icon_image launch_image fill_bg_color [dst_dir]"; exit 1; }
ICON=$(readlink -f ${1:-"icon.png"})
ICON_ALT=$(readlink -f ${5:-"icon-alt.png"})
LAUNCH=$(readlink -f ${2:-"launch.png"})
FILL_COLOUR=${3:-"none"}
OUTPUT=${4:-"out"}
CONVERT="magick -background none"
if [ ! -f "$ICON" ]; then
usage
fi
echo "USING:"
echo " icon=$ICON"
echo " icon-alt=$ICON_ALT"
echo " launch=$LAUNCH"
# set -x
# Directories
# -------------------------------------------
SCRIPTDIR=`dirname $0`
WORKINGDIR=`PWD`
ASSETSDIR=${WORKINGDIR}/.air-icon-generation-assets
ASSETSSRCDIR=${ASSETSDIR}/src
ASSETSWORKING=${ASSETSDIR}/build
mkdir -p "${OUTPUT}" 2>/dev/null
mkdir -p "${ASSETSSRCDIR}" 2>/dev/null
OUTPUTDIR=$(readlink -f ${OUTPUT})
if [ ! -d "${OUTPUTDIR}" ]; then
echo "No output dir: ${OUTPUTDIR}"
usage
fi
# Download xcassets
# -------------------------------------------
if [ ! -d "${ASSETSSRCDIR}/Assets.xcassets" ]; then
echo "Downloading assets"
until $(curl -L "https://github.com/distriqt/AIR-ImageScripts/blob/master/generate-assets.zip?raw=true" --output .tmp.generate-assets.zip); do
printf '.'
sleep 5
done
# curl -L "https://github.com/distriqt/AIR-ImageScripts/blob/master/generate-assets.zip?raw=true" --output .tmp.generate-assets.zip
unzip -qq -o .tmp.generate-assets.zip -d "${ASSETSSRCDIR}"
rm -Rf .tmp.generate-assets.zip
fi
# App Icons
# -------------------------------------------
echo "Generating icons"
ICONDIR=${OUTPUTDIR}/icons
mkdir -p "${ICONDIR}"
$CONVERT "$ICON" -resize 16x16 "$ICONDIR/icon16x16.png"
$CONVERT "$ICON" -resize 20x20 "$ICONDIR/icon20x20.png"
$CONVERT "$ICON" -resize 29x29 "$ICONDIR/icon29x29.png"
$CONVERT "$ICON" -resize 32x32 "$ICONDIR/icon32x32.png"
$CONVERT "$ICON" -resize 36x36 "$ICONDIR/icon36x36.png"
$CONVERT "$ICON" -resize 40x40 "$ICONDIR/icon40x40.png"
$CONVERT "$ICON" -resize 48x48 "$ICONDIR/icon48x48.png"
$CONVERT "$ICON" -resize 57x57 "$ICONDIR/icon57x57.png"
$CONVERT "$ICON" -resize 58x58 "$ICONDIR/icon58x58.png"
$CONVERT "$ICON" -resize 60x60 "$ICONDIR/icon60x60.png"
$CONVERT "$ICON" -resize 64x64 "$ICONDIR/icon64x64.png"
$CONVERT "$ICON" -resize 72x72 "$ICONDIR/icon72x72.png"
$CONVERT "$ICON" -resize 76x76 "$ICONDIR/icon76x76.png"
$CONVERT "$ICON" -resize 80x80 "$ICONDIR/icon80x80.png"
$CONVERT "$ICON" -resize 87x87 "$ICONDIR/icon87x87.png"
$CONVERT "$ICON" -resize 114x114 "$ICONDIR/icon114x114.png"
$CONVERT "$ICON" -resize 120x120 "$ICONDIR/icon120x120.png"
$CONVERT "$ICON" -resize 128x128 "$ICONDIR/icon128x128.png"
$CONVERT "$ICON" -resize 144x144 "$ICONDIR/icon144x144.png"
$CONVERT "$ICON" -resize 152x152 "$ICONDIR/icon152x152.png"
$CONVERT "$ICON" -resize 167x167 "$ICONDIR/icon167x167.png"
$CONVERT "$ICON" -resize 180x180 "$ICONDIR/icon180x180.png"
$CONVERT "$ICON" -resize 256x256 "$ICONDIR/icon512x512.png"
$CONVERT "$ICON" -resize 512x512 "$ICONDIR/icon512x512.png"
$CONVERT "$ICON" -resize 1024x1024 "$ICONDIR/icon1024x1024.png"
# Assets.car
# -------------------------------------------
echo "Generating Assets.car"
echo " - Assets.car: Icons"
TMPDIR=${WORKINGDIR}/.air-icon-generation-tmp
if [ -d "${TMPDIR}" ]; then
echo "delete ${TMPDIR}"
rm -Rf "${TMPDIR}"
fi
mkdir "${TMPDIR}" 2>/dev/null
if [ -d "${ASSETSWORKING}" ]; then
echo "delete ${ASSETSWORKING}"
rm -Rf "${ASSETSWORKING}"
fi
cp -Rf "${ASSETSSRCDIR}" "${ASSETSWORKING}"
generate_appicon () {
ICONSRC=$1
ICONNAME=$2
APPICONSETSRC="${ASSETSSRCDIR}/Assets.xcassets/AppIcon.appiconset"
APPICONSET="${ASSETSWORKING}/Assets.xcassets/${ICONNAME}.appiconset"
if [ ! -d "${APPICONSET}" ]; then
echo "generate_appicon: ${ICONNAME}.appiconset doesn't exist - creating new icon set"
mkdir "${APPICONSET}"
fi
cp -Rf "${ASSETSSRCDIR}/Assets.xcassets/AppIcon.appiconset/Contents.json" "${APPICONSET}/Contents.json"
sed -i.bak "s/Icon-App/${ICONNAME}/" "${APPICONSET}/Contents.json"
rm -f ${APPICONSET}/Icon-App*
rm -f ${APPICONSET}/Contents.json.bak
# $CONVERT "${ICONSRC}" -resize 20x20 "${APPICONSET}/${ICONNAME}-20x20@1x.png"
$CONVERT "${ICONSRC}" -resize 40x40 "${APPICONSET}/${ICONNAME}-20x20@2x.png"
$CONVERT "${ICONSRC}" -resize 60x60 "${APPICONSET}/${ICONNAME}-20x20@3x.png"
# $CONVERT "${ICONSRC}" -resize 29x29 "${APPICONSET}/${ICONNAME}-29x29@1x.png"
$CONVERT "${ICONSRC}" -resize 58x58 "${APPICONSET}/${ICONNAME}-29x29@2x.png"
$CONVERT "${ICONSRC}" -resize 136x136 "${APPICONSET}/${ICONNAME}-68x68@2x.png"
$CONVERT "${ICONSRC}" -resize 87x87 "${APPICONSET}/${ICONNAME}-29x29@3x.png"
# $CONVERT "${ICONSRC}" -resize 40x40 "${APPICONSET}/${ICONNAME}-40x40@1x.png"
$CONVERT "${ICONSRC}" -resize 80x80 "${APPICONSET}/${ICONNAME}-40x40@2x.png"
$CONVERT "${ICONSRC}" -resize 120x120 "${APPICONSET}/${ICONNAME}-40x40@3x.png"
# $CONVERT "${ICONSRC}" -resize 120x120 "${APPICONSET}/${ICONNAME}-60x60@2x.png"
$CONVERT "${ICONSRC}" -resize 180x180 "${APPICONSET}/${ICONNAME}-60x60@3x.png"
$CONVERT "${ICONSRC}" -resize 128x128 "${APPICONSET}/${ICONNAME}-64x64@2x.png"
$CONVERT "${ICONSRC}" -resize 192x192 "${APPICONSET}/${ICONNAME}-64x64@3x.png"
$CONVERT "${ICONSRC}" -resize 114x114 "${APPICONSET}/${ICONNAME}-38x38@3x.png"
$CONVERT "${ICONSRC}" -resize 76x76 "${APPICONSET}/${ICONNAME}-76x76@1x.png"
$CONVERT "${ICONSRC}" -resize 152x152 "${APPICONSET}/${ICONNAME}-76x76@2x.png"
$CONVERT "${ICONSRC}" -resize 167x167 "${APPICONSET}/${ICONNAME}-83.5x83.5@2x.png"
$CONVERT "${ICONSRC}" -resize 1024x1024 "${APPICONSET}/iTunesArtwork@2x.png"
echo " - Assets.car: ${ICONNAME} created"
}
generate_appicon "${ICON}" "AppIcon"
# If you have an "icon-alt.png" in the directory this will add an alternate icon to the asset catalogue (for dynamic icons)
# To add another duplicate this section and change the source and name of the icon
if [ -f "$ICON_ALT" ]; then
generate_appicon "${ICON_ALT}" "AlternateIcon"
fi
echo " - Assets.car: launch screen"
LAUNCHSET=$ASSETSWORKING/Assets.xcassets/LaunchImage.imageset
if [ -f "${LAUNCH}" ]; then
magick ${LAUNCH} -resize 2400x2400 "${LAUNCHSET}/LaunchImage.png" 2>/dev/null
else
magick ${ICON} -background ${FILL_COLOUR} -gravity center -resize 1024x1024 -extent 2400x2400 "${LAUNCHSET}/LaunchImage.png"
fi
echo " - Assets.car: actool"
xcrun actool "${ASSETSWORKING}/Assets.xcassets" --compile "${TMPDIR}" \
--platform iphoneos \
--minimum-deployment-target 12.0 \
--include-all-app-icons \
--app-icon AppIcon \
--output-partial-info-plist "${TMPDIR}/partial.plist" 1>/dev/null 2>/dev/null
echo " - Assets.car: actool complete"
cp -Rf "${TMPDIR}/Assets.car" "${OUTPUTDIR}/."
cp -Rf "${ASSETSWORKING}/LaunchScreen.storyboardc" "${OUTPUTDIR}/."
echo "========== COMPLETE =============="
# List contents of asset catalogue
#xcrun --sdk iphoneos assetutil --info "${OUTPUTDIR}/Assets.car"