-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icons.sh
executable file
·137 lines (123 loc) · 10 KB
/
icons.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
#! /bin/sh
function print_example() {
echo "Example"
echo " icons ios ~/AppIcon.pdf ~/Icons/"
}
function print_usage() {
echo "Usage"
echo " icons <ios|watch|complication|macos> in-file.pdf (out-dir)"
}
function command_exists() {
if type "$1" >/dev/null 2>&1; then
return 1
else
return 0
fi
}
if command_exists "sips" == 0 ; then
echo "sips tool not found"
exit 1
fi
if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
print_usage
exit 0
fi
PLATFORM="$1"
FILE="$2"
if [ -z "$PLATFORM" ] || [ -z "$FILE" ] ; then
echo "Error: missing arguments"
echo ""
print_usage
echo ""
print_example
exit 1
fi
DIR="$3"
if [ -z "$DIR" ] ; then
DIR=$(dirname $FILE)
fi
# Create directory if needed
mkdir -p "$DIR"
if [[ "$PLATFORM" == *"ios"* ]] ; then # iOS
sips -s format png -Z '180' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '29' "${FILE}" --out "${DIR}"/iPadSettings.png
sips -s format png -Z '58' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '58' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '120' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '87' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '40' "${FILE}" --out "${DIR}"/iPadSpotlight.png
sips -s format png -Z '80' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '80' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '120' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '76' "${FILE}" --out "${DIR}"/iPad.png
sips -s format png -Z '152' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '167' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '40' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '60' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '20' "${FILE}" --out "${DIR}"/iPadNotification.png
sips -s format png -Z '40' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '1024' "${FILE}" --out "${DIR}"/AppStoreMarketing.png
# https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_ref-Asset_Catalog_Format/AppIconType.html
contents_json='{"images":[{"size":"20x20","idiom":"iphone","filename":"[email protected]","scale":"2x"},{"size":"20x20","idiom":"iphone","filename":"[email protected]","scale":"3x"},{"size":"29x29","idiom":"iphone","filename":"[email protected]","scale":"2x"},{"size":"29x29","idiom":"iphone","filename":"[email protected]","scale":"3x"},{"size":"40x40","idiom":"iphone","filename":"[email protected]","scale":"2x"},{"size":"40x40","idiom":"iphone","filename":"[email protected]","scale":"3x"},{"size":"60x60","idiom":"iphone","filename":"[email protected]","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"[email protected]","scale":"3x"},{"size":"20x20","idiom":"ipad","filename":"iPadNotification.png","scale":"1x"},{"size":"20x20","idiom":"ipad","filename":"[email protected]","scale":"2x"},{"size":"29x29","idiom":"ipad","filename":"iPadSettings.png","scale":"1x"},{"size":"29x29","idiom":"ipad","filename":"[email protected]","scale":"2x"},{"size":"40x40","idiom":"ipad","filename":"iPadSpotlight.png","scale":"1x"},{"size":"40x40","idiom":"ipad","filename":"[email protected]","scale":"2x"},{"size":"76x76","idiom":"ipad","filename":"iPad.png","scale":"1x"},{"size":"76x76","idiom":"ipad","filename":"[email protected]","scale":"2x"},{"size":"83.5x83.5","idiom":"ipad","filename":"[email protected]","scale":"2x"},{"size":"1024x1024","idiom":"ios-marketing","filename":"AppStoreMarketing.png","scale":"1x"}],"info":{"version":1,"author":"xcode"}}'
echo $contents_json > "${DIR}"/Contents.json
fi
if [[ "$PLATFORM" == *"watch"* ]] ; then # Apple Watch
sips -s format png -Z '48' "${FILE}" --out "${DIR}"/Watch38mmNotificationCenter.png
sips -s format png -Z '55' "${FILE}" --out "${DIR}"/Watch42mmNotificationCenter.png
sips -s format png -Z '66' "${FILE}" --out "${DIR}"/Watch45mmNotificationCenter.png
sips -s format png -Z '58' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '87' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '80' "${FILE}" --out "${DIR}"/Watch38MM42MMHomeScreen.png
sips -s format png -Z '88' "${FILE}" --out "${DIR}"/Watch40MMHomeScreen.png
sips -s format png -Z '92' "${FILE}" --out "${DIR}"/Watch41MMHomeScreen.png
sips -s format png -Z '100' "${FILE}" --out "${DIR}"/Watch44MMHomeScreen.png
sips -s format png -Z '102' "${FILE}" --out "${DIR}"/Watch45MMHomeScreen.png
sips -s format png -Z '172' "${FILE}" --out "${DIR}"/Watch38MMShortLook.png
sips -s format png -Z '196' "${FILE}" --out "${DIR}"/Watch40MM42MMShortLook.png
sips -s format png -Z '216' "${FILE}" --out "${DIR}"/Watch44MMShortLook.png
sips -s format png -Z '234' "${FILE}" --out "${DIR}"/Watch45MMShortLook.png
sips -s format png -Z '1024' "${FILE}" --out "${DIR}"/WatchAppStore.png
# https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_ref-Asset_Catalog_Format/AppIconType.html
contents_json='{"images":[{"filename":"Watch38mmNotificationCenter.png","idiom":"watch","role":"notificationCenter","scale":"2x","size":"24x24","subtype":"38mm"},{"filename":"Watch42mmNotificationCenter.png","idiom":"watch","role":"notificationCenter","scale":"2x","size":"27.5x27.5","subtype":"42mm"},{"filename":"[email protected]","idiom":"watch","role":"companionSettings","scale":"2x","size":"29x29"},{"filename":"[email protected]","idiom":"watch","role":"companionSettings","scale":"3x","size":"29x29"},{"filename":"Watch45mmNotificationCenter.png","idiom":"watch","role":"notificationCenter","scale":"2x","size":"33x33","subtype":"45mm"},{"filename":"Watch38MM42MMHomeScreen.png","idiom":"watch","role":"appLauncher","scale":"2x","size":"40x40","subtype":"38mm"},{"filename":"Watch40MMHomeScreen.png","idiom":"watch","role":"appLauncher","scale":"2x","size":"44x44","subtype":"40mm"},{"filename":"Watch41MMHomeScreen.png","idiom":"watch","role":"appLauncher","scale":"2x","size":"46x46","subtype":"41mm"},{"filename":"Watch44MMHomeScreen.png","idiom":"watch","role":"appLauncher","scale":"2x","size":"50x50","subtype":"44mm"},{"filename":"Watch45MMHomeScreen.png","idiom":"watch","role":"appLauncher","scale":"2x","size":"51x51","subtype":"45mm"},{"filename":"Watch38MMShortLook.png","idiom":"watch","role":"quickLook","scale":"2x","size":"86x86","subtype":"38mm"},{"filename":"Watch40MM42MMShortLook.png","idiom":"watch","role":"quickLook","scale":"2x","size":"98x98","subtype":"42mm"},{"filename":"Watch44MMShortLook.png","idiom":"watch","role":"quickLook","scale":"2x","size":"108x108","subtype":"44mm"},{"filename":"Watch45MMShortLook.png","idiom":"watch","role":"quickLook","scale":"2x","size":"117x117","subtype":"45mm"},{"filename":"WatchAppStore.png","idiom":"watch-marketing","scale":"1x","size":"1024x1024"}],"info":{"author":"xcode","version":1}}'
echo $contents_json > "${DIR}"/Contents.json
fi
if [[ "$PLATFORM" == *"complication"* ]] ; then # Apple Watch
sips -s format png -Z '32' "${FILE}" --out "${DIR}"/Circular38mm2x.png
sips -s format png -Z '36' "${FILE}" --out "${DIR}"/Circular40mm2x.png
sips -s format png -Z '36' "${FILE}" --out "${DIR}"/Circular42mm2x.png
sips -s format png -Z '40' "${FILE}" --out "${DIR}"/Circular44mm2x.png
sips -s format png -Z '182' "${FILE}" --out "${DIR}"/ExtraLarge38mm2x.png
sips -s format png -Z '203' "${FILE}" --out "${DIR}"/ExtraLarge40mm2x.png
sips -s format png -Z '203' "${FILE}" --out "${DIR}"/ExtraLarge42mm2x.png
sips -s format png -Z '224' "${FILE}" --out "${DIR}"/ExtraLarge44mm2x.png
sips -s format png -Z '84' "${FILE}" --out "${DIR}"/GraphicBezel40mm2x.png
sips -s format png -Z '84' "${FILE}" --out "${DIR}"/GraphicBezel42mm2x.png
sips -s format png -Z '94' "${FILE}" --out "${DIR}"/GraphicBezel44mm2x.png
sips -s format png -Z '84' "${FILE}" --out "${DIR}"/GraphicCircular40mm2x.png
sips -s format png -Z '84' "${FILE}" --out "${DIR}"/GraphicCircular42mm2x.png
sips -s format png -Z '94' "${FILE}" --out "${DIR}"/GraphicCircular44mm2x.png
sips -s format png -Z '40' "${FILE}" --out "${DIR}"/GraphicCorner40mm2x.png
sips -s format png -Z '40' "${FILE}" --out "${DIR}"/GraphicCorner42mm2x.png
sips -s format png -Z '44' "${FILE}" --out "${DIR}"/GraphicCorner44mm2x.png
sips -s format png -Z '52' "${FILE}" --out "${DIR}"/GraphicModular38mm2x.png
sips -s format png -Z '58' "${FILE}" --out "${DIR}"/GraphicModular40mm2x.png
sips -s format png -Z '58' "${FILE}" --out "${DIR}"/GraphicModular42mm2x.png
sips -s format png -Z '64' "${FILE}" --out "${DIR}"/GraphicModular44mm2x.png
sips -s format png -Z '40' "${FILE}" --out "${DIR}"/GraphicUtilitarian38mm2x.png
sips -s format png -Z '44' "${FILE}" --out "${DIR}"/GraphicUtilitarian40mm2x.png
sips -s format png -Z '44' "${FILE}" --out "${DIR}"/GraphicUtilitarian42mm2x.png
sips -s format png -Z '50' "${FILE}" --out "${DIR}"/GraphicUtilitarian44mm2x.png
echo "NOTE: Graphic Extra Large is not generated since that is not rectangular"
fi
if [[ "$PLATFORM" == *"macos"* ]] ; then # macOS
sips -s format png -Z '1024' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '512' "${FILE}" --out "${DIR}"/icon_512x512.png
sips -s format png -Z '512' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '256' "${FILE}" --out "${DIR}"/icon_256x256.png
sips -s format png -Z '256' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '128' "${FILE}" --out "${DIR}"/icon_128x128.png
sips -s format png -Z '64' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '32' "${FILE}" --out "${DIR}"/icon_32x32.png
sips -s format png -Z '32' "${FILE}" --out "${DIR}"/[email protected]
sips -s format png -Z '16' "${FILE}" --out "${DIR}"/icon_16x16.png
fi