-
Notifications
You must be signed in to change notification settings - Fork 1
/
icns_creator.sh
executable file
·80 lines (70 loc) · 1.65 KB
/
icns_creator.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
#!/bin/bash
# Copyright https://github.com/jamf/icns-Creator
# Creates an icns file from a source image
src_image="$1"
if [ -z "$1" ]; then
echo "No source image was passed to this script"
exit 1
fi
icns_name="$2"
if [ -z "$2" ]; then
icns_name="iconbuilder"
fi
if [ "${src_image:(-3)}" != "png" ]; then
echo "Source image is not a PNG, making a converted copy..."
/usr/bin/sips -s format png "$src_image" --out "${src_image}.png"
if [ $? -ne 0 ]; then
echo "The source image could not be converted to PNG format."
exit 1
fi
src_image="${src_image}.png"
fi
iconset_path="./${icns_name}.iconset"
if [ -e "$iconset_path" ]; then
/bin/rm -r "$iconset_path"
if [ $? -ne 0 ]; then
echo "There is a pre-existing file/dir $iconset_path the could not be deleted"
exit 1
fi
fi
/bin/mkdir "$iconset_path"
icon_file_list=(
"icon_16x16.png"
"icon_16x16@2x.png"
"icon_32x32.png"
"icon_32x32@2x.png"
"icon_128x128.png"
"icon_128x128@2x.png"
"icon_256x256.png"
"icon_256x256@2x.png"
"icon_512x512.png"
"icon_512x512@2x.png"
)
icon_size=(
'16'
'32'
'32'
'64'
'128'
'256'
'256'
'512'
'512'
'1024'
)
counter=0
for a in ${icon_file_list[@]}; do
icon="${iconset_path}/${a}"
/bin/cp "$src_image" "$icon"
icon_size=${icon_size[$counter]}
/usr/bin/sips -z $icon_size $icon_size "$icon"
counter=$(($counter + 1))
done
echo "Creating .icns file from $iconset_path"
/usr/bin/iconutil -c icns "$iconset_path"
if [ $? -ne 0 ]; then
echo "There was an error creating the .icns file"
exit 1
fi
echo "Done"
exit 0