2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-02 04:40:48 +00:00
nativefier/bin/convertToIcns
David Kramer dc257052c5 Fix #199 - macOS: Perform image conversion tasks using sips when available (PR #583)
Eliminates the requirement for imagemagick to be present on macOS for icon conversion.
Based off of the code from PR #279.
2018-04-26 07:42:03 -04:00

55 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
### USAGE
# ./convertToIcns <input png> <outp icns>
# Example
# ./convertToIcns ~/sample.png ~/Desktop/converted.icns
# exit the shell script on error immediately
set -e
# Exec Paths
HAVE_IMAGEMAGICK=
HAVE_ICONUTIL=
HAVE_SIPS=
type convert &>/dev/null && HAVE_IMAGEMAGICK=true
type iconutil &>/dev/null && HAVE_ICONUTIL=true
type sips &>/dev/null && HAVE_SIPS=true
[[ -z "$HAVE_ICONUTIL" ]] && { echo >&2 "Cannot find required iconutil executable"; exit 1; }
[[ -z "$HAVE_IMAGEMAGICK" && -z "$HAVE_SIPS" ]] && { echo >&2 "Cannot find required image converter, please install sips or imagemagick"; exit 1; }
# Parameters
SOURCE="$1"
DEST="$2"
# Check source and destination arguments
if [ -z "${SOURCE}" ]; then
echo "No source image specified"
exit 1
fi
if [ -z "${DEST}" ]; then
echo "No destination specified"
exit 1
fi
TEMP_DIR="$(mktemp -d)"
ICONSET="${TEMP_DIR}/converted.iconset"
function cleanUp() {
rm -rf "${TEMP_DIR}"
}
trap cleanUp EXIT
"${BASH_SOURCE%/*}/convertToIconset" "${SOURCE}" "${ICONSET}"
# Create an icns file lefrom the iconset
iconutil -c icns "${ICONSET}" -o "${DEST}"
trap - EXIT
cleanUp