Skip to content

Instantly share code, notes, and snippets.

@JamesBoon
Last active March 10, 2022 09:08
Show Gist options
  • Save JamesBoon/59bbf2cf21582e5284382678b2e5bc12 to your computer and use it in GitHub Desktop.
Save JamesBoon/59bbf2cf21582e5284382678b2e5bc12 to your computer and use it in GitHub Desktop.
A bash script to create a `favicon.ico` via Imagemagick

A bash script to create a favicon.ico via Imagemagick.

Usage:

./favicon.sh myimage.png

Creates a favicon.ico file in the same folder.

#!/bin/bash
set -e
#
# Create a favicon.ico from any image
#
# requires Imagemagick
# https://legacy.imagemagick.org/Usage/thumbnails/#favicon
#
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
#-- Help
if [ -z "$1" ]; then
echo
echo "Error: image file required"
fi
echo
echo "Usage: \"$0 <image>\""
echo " image - Can be any image file, but square PNGs work best."
echo
exit
fi
convert $1 -background white \
\( -clone 0 -resize 16x16 -extent 16x16 \) \
\( -clone 0 -resize 32x32 -extent 32x32 \) \
\( -clone 0 -resize 48x48 -extent 48x48 \) \
\( -clone 0 -resize 64x64 -extent 64x64 \) \
-delete 0 -alpha off -colors 256 favicon.ico
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment