Skip to content

Instantly share code, notes, and snippets.

@jmeyo
Forked from lavoiesl/favicon.sh
Last active December 31, 2015 01:29
Show Gist options
  • Save jmeyo/7914873 to your computer and use it in GitHub Desktop.
Save jmeyo/7914873 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Converts an image in a multi-resolution favicon
# Requires Imagemagick
function generate_favicon() {
command -v convert >/dev/null 2>&1 || (echo "Imagemagick not here, install it" && return )
case "$#" in
"0")
echo "Usage: $FUNCNAME input.png output.ico"
echo -e "\t or $FUNCNAME input.png"
echo "Work with png, jpg and jpeg file"
return
;;
"1")
input="$1"
# rename jpg, jpeg and png to output ico
output="${input/.png/.ico}"
output="${output/.jpg/.ico}"
output="${output/.jpeg/.ico}"
;;
"2")
input="$1"
output="$2"
;;
esac
sizes="16 32 64 128 256"
tmp_dir=$(mktemp -d /tmp/favicon.XXXXXXXXXX)
files=""
for size in $sizes; do
file="$tmp_dir/$size.png"
convert "$input" -depth 8 -background transparent -flatten -resize "${size}x${size}" "$file"
files="$files $file"
done
convert $files $output
rm -R $tmp_dir
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment