#!/bin/sh
##
##  png2ico.sh -- PNG to ICO(N) format conversion with ImageMagick
##  Copyright (c) 2014 Ralf S. Engelschall <rse@engelschall.com>
##
##  See Also:
##  - http://en.wikipedia.org/wiki/ICO_%28file_format%29
##  - http://en.wikipedia.org/wiki/Favicon
##

#   sanity check usage
if [ $# -ne 2 ]; then
    echo "USAGE: png2ico <name>.{png|gif|...} <name>.ico" 1>&2
    exit 1
fi

#   run ImageMagick to perform the conversion
exec @l_prefix@/bin/convert \
    "$1" \
    -background transparent \
    -bordercolor transparent \
    -border 0 \
    -colors 256 \
    \( -clone 0 -resize x16 -gravity center -crop 16x16+0+0\! -flatten \) \
    \( -clone 0 -resize x32 -gravity center -crop 32x32+0+0\! -flatten \) \
    \( -clone 0 -resize x48 -gravity center -crop 48x48+0+0\! -flatten \) \
    \( -clone 0 -resize x64 -gravity center -crop 64x64+0+0\! -flatten \) \
    -delete 0 \
    "$2"

