Allow `.ico` to be changed into an `.icns`

Update shell script to support `.ico` files that contain sequential images
This commit is contained in:
Jia Hao 2016-03-08 23:58:38 +08:00
parent 3f6f632d51
commit f48ad3790b
2 changed files with 25 additions and 19 deletions

View File

@ -29,7 +29,7 @@ fi
SOURCE=$1
DEST=$2
# Get source image
# Check source and destination arguments
if [ -z "${SOURCE}" ]; then
echo "No source image specified"
exit 1
@ -41,13 +41,23 @@ if [ -z "${DEST}" ]; then
fi
# File Infrastructure
NAME=$(basename "${SOURCE}")
EXT="${NAME##*.}"
BASE="${NAME%.*}"
ICONSET="${BASE}.iconset"
mkdir "${ICONSET}"
# check if .ico is a sequence
IS_ICO_SET="$(identify ${SOURCE} | grep -e "\w\.ico\[0")"
if [ "${IS_ICO_SET}" ]; then
# extract the largest(?) image from the set
convert "${SOURCE}" "${ICONSET}/${BASE}.png"
SOURCE="${ICONSET}/${BASE}-0.png"
fi
# Debug Info
# echo "SOURCE: ${SOURCE}"
# echo "NAME: $NAME"
@ -71,7 +81,6 @@ ICONSET="${BASE}.iconset"
#fi
# Resample image into iconset
mkdir "${ICONSET}"
convert "${SOURCE}" -define png:big-depth=16 -define png:color-type=6 -sample 16x16 "${ICONSET}/icon_16x16.png"
convert "${SOURCE}" -define png:big-depth=16 -define png:color-type=6 -sample 32x32 "${ICONSET}/icon_16x16@2x.png"
@ -90,3 +99,4 @@ iconutil -c icns "${ICONSET}" -o ${DEST}
# Clean up the iconset
rm -rf "${ICONSET}"

View File

@ -42,23 +42,19 @@ function iconBuild(options, callback) {
return;
}
if (iconIsPng(options.icon)) {
if (!isOSX()) {
console.warn('Conversion of `.png` to `.icns` for OSX app is only supported on OSX');
returnCallback();
return;
}
pngToIcns(options.icon, (error, icnsPath) => {
options.icon = icnsPath;
if (error) {
console.warn('Skipping icon conversion from `.png` to `.icns`: ', error);
}
returnCallback();
return;
});
if (!isOSX()) {
console.warn('Conversion of `.png` to `.icns` for OSX app is only supported on OSX');
returnCallback();
return;
}
pngToIcns(options.icon, (error, icnsPath) => {
options.icon = icnsPath;
if (error) {
console.warn('Skipping icon conversion from `.png` to `.icns`: ', error);
}
returnCallback();
});
}
function iconIsPng(iconPath) {