From f48ad3790b678a6cec516754600bc2052ad9657a Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Tue, 8 Mar 2016 23:58:38 +0800 Subject: [PATCH] Allow `.ico` to be changed into an `.icns` Update shell script to support `.ico` files that contain sequential images --- bin/pngToIcns | 16 +++++++++++++--- src/build/iconBuild.js | 28 ++++++++++++---------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/bin/pngToIcns b/bin/pngToIcns index 97868a3..394a9b1 100755 --- a/bin/pngToIcns +++ b/bin/pngToIcns @@ -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}" + diff --git a/src/build/iconBuild.js b/src/build/iconBuild.js index 0622506..ca98723 100644 --- a/src/build/iconBuild.js +++ b/src/build/iconBuild.js @@ -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) {