Skip to content

Instantly share code, notes, and snippets.

@yrps
Last active February 15, 2016 18:28
Show Gist options
  • Select an option

  • Save yrps/b677c15c96937b44a481 to your computer and use it in GitHub Desktop.

Select an option

Save yrps/b677c15c96937b44a481 to your computer and use it in GitHub Desktop.
use ImageMagick to convert the given image to a favicon
#!/bin/sh
# use ImageMagick to convert the given image to a favicon
# http://www.imagemagick.org/Usage/thumbnails/#favicon
usage() {
>&2 echo "usage: $(basename "$0") input [output]"
}
set -eu
input="${1:-}"
output="${2:=favicon}"
ext=".ico"
# input filename is required
if [ ! -r "$input" ]; then
usage
exit 1
fi
# append file extension if necessary
[ "${2: -4}" != "$ext" ] && output=${output}${ext}
[ -f "$output" ] && echo "overwriting output file $output"
convert "$input" \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 64x64 \) \
-delete 0 -alpha remove -colors 256 "$output"
if [ "$?" ]; then
identify "$output"
else
>&2 echo "error converting"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment