-
-
Save jmeyo/7914873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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