2018-04-26 13:49:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-03-11 05:05:54 +00:00
|
|
|
|
|
|
|
# USAGE
|
|
|
|
|
|
|
|
# ./convertToIco <input png or ico> <outfilename>.ico
|
|
|
|
# Example
|
|
|
|
# ./convertToPng ~/sample.png ~/converted.ico
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-02-28 19:21:28 +00:00
|
|
|
CONVERT=
|
|
|
|
|
|
|
|
type gm &>/dev/null && gm version | grep GraphicsMagick &>/dev/null && CONVERT="gm convert"
|
|
|
|
type convert &>/dev/null && CONVERT="convert"
|
|
|
|
|
|
|
|
[[ -z "$CONVERT" ]] && { echo >&2 "Cannot find required ImageMagick Convert or GraphicsMagick executable"; exit 1; }
|
2016-03-11 05:05:54 +00:00
|
|
|
|
|
|
|
SOURCE=$1
|
|
|
|
DEST=$2
|
|
|
|
|
|
|
|
if [ -z "${SOURCE}" ]; then
|
|
|
|
echo "No source image specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${DEST}" ]; then
|
|
|
|
echo "No destination specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
NAME=$(basename "${SOURCE}")
|
|
|
|
EXT="${NAME##*.}"
|
|
|
|
|
|
|
|
if [ "${EXT}" == "ico" ]; then
|
|
|
|
cp "${SOURCE}" "${DEST}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-02-28 19:21:28 +00:00
|
|
|
$CONVERT "${SOURCE}" -resize 256x256 "${DEST}"
|