This repository was archived by the owner on Apr 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathmakeicns
executable file
·73 lines (62 loc) · 1.47 KB
/
makeicns
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
#!/bin/bash
readonly program="$(basename "${0}")"
function usage {
echo "
Generate an icns icon from a png.
Usage:
${program} [options] <file>
Options:
-i, --input <file> File to convert.
-o, --output <file> File to save.
-h, --help Show this message.
" | sed -E 's/^ {4}//'
exit "${1}"
}
# Options
args=()
while [[ "${1}" ]]
do
case "${1}" in
-h | --help)
usage 0
;;
-i | --input)
readonly input="$(realpath "${2}")"
shift
;;
-o | --output)
readonly output="${2%.icns}.icns" # Add extension if missing
shift
;;
--)
shift
args+=("${@}")
break
;;
-*)
echo "Unrecognised option: ${1}"
exit 1
;;
*)
args+=("${1}")
;;
esac
shift
done
set -- "${args[@]}"
# Checks
[[ -f "${input}" && -n "${output}" ]] || usage 1
# Main
readonly iconset="$(mktemp -d)"
if [[ "$(/usr/bin/file --mime-type --brief "${input}")" != 'image/png' ]]
then
echo 'Image needs to be a png.' >&2
exit 1
fi
for size in {16,32,64,128,256,512}
do
/usr/bin/sips --resampleHeightWidth "${size}" "${size}" "${input}" --out "${iconset}/icon_${size}x${size}.png" &> /dev/null
/usr/bin/sips --resampleHeightWidth "$((size * 2))" "$((size * 2))" "${input}" --out "${iconset}/icon_${size}x${size}@2x.png" &> /dev/null
done
/bin/mv "${iconset}" "${iconset}.iconset"
/usr/bin/iconutil --convert icns "${iconset}.iconset" --output "${output}"