This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathconvertToIcns
executable file
·68 lines (56 loc) · 1.88 KB
/
convertToIcns
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
#!/bin/sh
# USAGE
# =====
# ./convertToIcns <input.svg or input.png> <output.icns>
# Example:
# ./convertToIcns ~/icon.png ~/Desktop/icon_converted.icns
# Exit the shell script on error immediately
set -e
# Check for dependency
# iconutil
type iconutil >/dev/null 2>&1 || { echo >&2 "Cannot find required iconutil executable"; exit 1; }
# Import script as variable
CONVERT_TO_PNG="${BASH_SOURCE%/*}/convertToPng"
# Arguments
SOURCE=$1
DEST=$2
# Check arguments
if [ -z "${SOURCE}" ]; then
echo "No source image specified"
exit 1
fi
if [ -z "${DEST}" ]; then
echo "No destination specified"
exit 1
fi
# File variables
SOURCE_NAME=$(basename "${SOURCE}")
SOURCE_EXT="${SOURCE_NAME##*.}"
SOURCE_BASE="${SOURCE_NAME%.*}"
ICONSET="${SOURCE_BASE}.iconset"
# Temp directory
TEMP_DIR=".convertToIcns"
mkdir -p "${TEMP_DIR}/${ICONSET}"
# Cleanup
function cleanUp() {
rm -rf "${TEMP_DIR}"
}
trap cleanUp EXIT
# Check for file type
if [ "${SOURCE_EXT}" == "svg" ] || [ "${SOURCE_EXT}" == "png" ]; then
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_16x16.png" 16
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_16x16@2x.png" 32
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_32x32.png" 32
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_32x32@2x.png" 64
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_128x128.png" 128
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_128x128@2x.png" 256
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_256x256.png" 256
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_256x256@2x.png" 512
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_512x512.png" 512
${CONVERT_TO_PNG} "${SOURCE}" "${TEMP_DIR}/${ICONSET}/icon_512x512@2x.png" 1024
else
echo "SVG or PNG must be provided"
exit 1
fi
# Create an icns file from the iconset
iconutil -c icns "${TEMP_DIR}/${ICONSET}" -o "${DEST}"