UNPKG

1.16 kBPlain TextView Raw
1#!/usr/bin/env bash
2
3### USAGE
4
5# ./convertToIcns <input png> <outp icns>
6# Example
7# ./convertToIcns ~/sample.png ~/Desktop/converted.icns
8
9# exit the shell script on error immediately
10set -e
11
12# Exec Paths
13HAVE_IMAGEMAGICK=
14HAVE_ICONUTIL=
15HAVE_SIPS=
16
17type convert &>/dev/null && HAVE_IMAGEMAGICK=true
18type iconutil &>/dev/null && HAVE_ICONUTIL=true
19type sips &>/dev/null && HAVE_SIPS=true
20
21[[ -z "$HAVE_ICONUTIL" ]] && { echo >&2 "Cannot find required iconutil executable"; exit 1; }
22[[ -z "$HAVE_IMAGEMAGICK" && -z "$HAVE_SIPS" ]] && { echo >&2 "Cannot find required image converter, please install sips or imagemagick"; exit 1; }
23
24# Parameters
25SOURCE="$1"
26DEST="$2"
27
28# Check source and destination arguments
29if [ -z "${SOURCE}" ]; then
30 echo "No source image specified"
31 exit 1
32fi
33
34if [ -z "${DEST}" ]; then
35 echo "No destination specified"
36 exit 1
37fi
38
39TEMP_DIR="$(mktemp -d)"
40ICONSET="${TEMP_DIR}/converted.iconset"
41
42function cleanUp() {
43 rm -rf "${TEMP_DIR}"
44}
45
46trap cleanUp EXIT
47
48"${BASH_SOURCE%/*}/convertToIconset" "${SOURCE}" "${ICONSET}"
49
50# Create an icns file lefrom the iconset
51iconutil -c icns "${ICONSET}" -o "${DEST}"
52
53trap - EXIT
54cleanUp