1584
|
1 |
#!/bin/bash
|
|
2 |
# Creates an icns file from a source image
|
|
3 |
|
|
4 |
src_image="$1"
|
|
5 |
if [ -z "$1" ]; then
|
|
6 |
echo "No source image was passed to this script"
|
|
7 |
exit 1
|
|
8 |
fi
|
|
9 |
|
|
10 |
icns_name="$2"
|
|
11 |
if [ -z "$2" ]; then
|
|
12 |
icns_name="iconbuilder"
|
|
13 |
fi
|
|
14 |
|
|
15 |
if [ "${src_image:(-3)}" != "png" ]; then
|
|
16 |
echo "Source image is not a PNG, making a converted copy..."
|
|
17 |
/usr/bin/sips -s format png "$src_image" --out "${src_image}.png"
|
|
18 |
if [ $? -ne 0 ]; then
|
|
19 |
echo "The source image could not be converted to PNG format."
|
|
20 |
exit 1
|
|
21 |
fi
|
|
22 |
src_image="${src_image}.png"
|
|
23 |
fi
|
|
24 |
|
|
25 |
iconset_path="./${icns_name}.iconset"
|
|
26 |
if [ -e "$iconset_path" ]; then
|
|
27 |
/bin/rm -r "$iconset_path"
|
|
28 |
if [ $? -ne 0 ]; then
|
|
29 |
echo "There is a pre-existing file/dir $iconset_path the could not be deleted"
|
|
30 |
exit 1
|
|
31 |
fi
|
|
32 |
fi
|
|
33 |
|
|
34 |
/bin/mkdir "$iconset_path"
|
|
35 |
|
|
36 |
icon_file_list=(
|
|
37 |
"icon_16x16.png"
|
|
38 |
"icon_16x16@2x.png"
|
|
39 |
"icon_32x32.png"
|
|
40 |
"icon_32x32@2x.png"
|
|
41 |
"icon_128x128.png"
|
|
42 |
"icon_128x128@2x.png"
|
|
43 |
"icon_256x256.png"
|
|
44 |
"icon_256x256@2x.png"
|
|
45 |
"icon_512x512.png"
|
|
46 |
"icon_512x512@2x.png"
|
|
47 |
)
|
|
48 |
|
|
49 |
icon_size=(
|
|
50 |
'16'
|
|
51 |
'32'
|
|
52 |
'32'
|
|
53 |
'64'
|
|
54 |
'128'
|
|
55 |
'256'
|
|
56 |
'256'
|
|
57 |
'512'
|
|
58 |
'512'
|
|
59 |
'1024'
|
|
60 |
)
|
|
61 |
|
|
62 |
counter=0
|
|
63 |
for a in ${icon_file_list[@]}; do
|
|
64 |
icon="${iconset_path}/${a}"
|
|
65 |
/bin/cp "$src_image" "$icon"
|
|
66 |
icon_size=${icon_size[$counter]}
|
|
67 |
/usr/bin/sips -z $icon_size $icon_size "$icon"
|
|
68 |
counter=$(($counter + 1))
|
|
69 |
done
|
|
70 |
|
|
71 |
echo "Creating .icns file from $iconset_path"
|
|
72 |
/usr/bin/iconutil -c icns "$iconset_path"
|
|
73 |
if [ $? -ne 0 ]; then
|
|
74 |
echo "There was an error creating the .icns file"
|
|
75 |
exit 1
|
|
76 |
fi
|
|
77 |
|
|
78 |
echo "Done"
|
|
79 |
exit 0
|