2016-01-27 02:22:22 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
### USAGE
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:50:45 +00:00
|
|
|
# ./convertToIcns <input png> <outp icns>
|
2016-01-27 02:22:22 +00:00
|
|
|
# Example
|
2016-03-10 07:50:45 +00:00
|
|
|
# ./convertToIcns ~/sample.png ~/Desktop/converted.icns
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
# exit the shell script on error immediately
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# import script as variable
|
|
|
|
CONVERT_TO_PNG="${BASH_SOURCE%/*}/convertToPng"
|
|
|
|
|
2016-01-27 02:22:22 +00:00
|
|
|
# Exec Paths
|
|
|
|
ICONUTIL=$(which iconutil)
|
2016-03-09 06:22:11 +00:00
|
|
|
IMAGEMAGICK_CONVERT=$(which convert)
|
|
|
|
|
2016-01-27 02:22:22 +00:00
|
|
|
if [ ! -x "${ICONUTIL}" ]; then
|
|
|
|
echo "Cannot find required iconutil executable" >&2
|
|
|
|
exit 1;
|
|
|
|
fi
|
2016-03-09 06:22:11 +00:00
|
|
|
if [ ! -x "${IMAGEMAGICK_CONVERT}" ]; then
|
2016-01-27 02:22:22 +00:00
|
|
|
echo "Cannot find required ImageMagick Convert executable" >&2
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Parameters
|
|
|
|
SOURCE=$1
|
2016-02-04 06:43:08 +00:00
|
|
|
DEST=$2
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-08 15:58:38 +00:00
|
|
|
# Check source and destination arguments
|
2016-01-27 02:22:22 +00:00
|
|
|
if [ -z "${SOURCE}" ]; then
|
|
|
|
echo "No source image specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-04 06:43:08 +00:00
|
|
|
if [ -z "${DEST}" ]; then
|
|
|
|
echo "No destination specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-01-27 02:22:22 +00:00
|
|
|
# File Infrastructure
|
|
|
|
NAME=$(basename "${SOURCE}")
|
|
|
|
EXT="${NAME##*.}"
|
|
|
|
BASE="${NAME%.*}"
|
2016-03-10 07:41:25 +00:00
|
|
|
TEMP_DIR="temp_icon"
|
2016-01-27 02:22:22 +00:00
|
|
|
ICONSET="${BASE}.iconset"
|
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
function cleanUp() {
|
|
|
|
rm -rf "${TEMP_DIR}"
|
|
|
|
rm -rf "${ICONSET}"
|
|
|
|
}
|
2016-03-08 15:58:38 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
trap cleanUp EXIT
|
2016-03-08 15:58:38 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
mkdir -p "${TEMP_DIR}"
|
|
|
|
mkdir -p "${ICONSET}"
|
2016-03-08 15:58:38 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
PNG_PATH="${TEMP_DIR}/icon.png"
|
|
|
|
${CONVERT_TO_PNG} "${SOURCE}" "${PNG_PATH}"
|
2016-01-27 02:22:22 +00:00
|
|
|
|
|
|
|
# Resample image into iconset
|
2016-03-10 07:41:25 +00:00
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 16x16 "${ICONSET}/icon_16x16.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 32x32 "${ICONSET}/icon_16x16@2x.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 32x32 "${ICONSET}/icon_32x32.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 64x64 "${ICONSET}/icon_32x32@2x.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 128x128 "${ICONSET}/icon_128x128.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 256x256 "${ICONSET}/icon_128x128@2x.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 256x256 "${ICONSET}/icon_256x256.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 512x512 "${ICONSET}/icon_256x256@2x.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 512x512 "${ICONSET}/icon_512x512.png"
|
|
|
|
convert "${PNG_PATH}" -define png:big-depth=16 -define png:color-type=6 -sample 1024x1024 "${ICONSET}/icon_512x512@2x.png"
|
2016-01-27 02:22:22 +00:00
|
|
|
|
|
|
|
# Create an icns file lefrom the iconset
|
2016-03-09 06:22:11 +00:00
|
|
|
iconutil -c icns "${ICONSET}" -o "${DEST}"
|
2016-01-27 02:22:22 +00:00
|
|
|
|
2016-03-10 07:41:25 +00:00
|
|
|
trap - EXIT
|
|
|
|
cleanUp
|