Nativefier/icon-scripts/convertToIcns

57 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2016-03-10 08:41:25 +01:00
### USAGE
2016-03-10 08:50:45 +01:00
# ./convertToIcns <input png> <outp icns>
# Example
2016-03-10 08:50:45 +01:00
# ./convertToIcns ~/sample.png ~/Desktop/converted.icns
2016-03-10 08:41:25 +01:00
# exit the shell script on error immediately
set -e
# Exec Paths
HAVE_IMAGEMAGICK=
HAVE_ICONUTIL=
HAVE_SIPS=
HAVE_GRAPHICSMAGICK=
type convert &>/dev/null && HAVE_IMAGEMAGICK=true
type iconutil &>/dev/null && HAVE_ICONUTIL=true
type sips &>/dev/null && HAVE_SIPS=true
type gm &>/dev/null && gm version | grep GraphicsMagick &>/dev/null && HAVE_GRAPHICSMAGICK=true
[[ -z "$HAVE_ICONUTIL" ]] && { echo >&2 "Cannot find required iconutil executable"; exit 1; }
[[ -z "$HAVE_IMAGEMAGICK" && -z "$HAVE_SIPS" && -z "$HAVE_GRAPHICSMAGICK" ]] && { echo >&2 "Cannot find required image converter, please install sips, imagemagick or graphicsmagick"; exit 1; }
# Parameters
SOURCE="$1"
DEST="$2"
# Check source and destination arguments
if [ -z "${SOURCE}" ]; then
echo "No source image specified"
exit 1
fi
2016-02-04 07:43:08 +01:00
if [ -z "${DEST}" ]; then
echo "No destination specified"
exit 1
fi
TEMP_DIR="$(mktemp -d -t nativefier-icns-XXXXXX)"
ICONSET="${TEMP_DIR}/converted.iconset"
2016-03-10 08:41:25 +01:00
function cleanUp() {
rm -rf "${TEMP_DIR}"
}
2016-03-10 08:41:25 +01:00
trap cleanUp EXIT
"${BASH_SOURCE%/*}/convertToIconset" "${SOURCE}" "${ICONSET}"
# Create an icns file lefrom the iconset
2016-03-09 07:22:11 +01:00
iconutil -c icns "${ICONSET}" -o "${DEST}"
2016-03-10 08:41:25 +01:00
trap - EXIT
cleanUp