Skip to content

Instantly share code, notes, and snippets.

@ifthenelse
Last active April 19, 2026 15:44
Show Gist options
  • Select an option

  • Save ifthenelse/0dc2cfe5d15a22d0bb787b76da02d215 to your computer and use it in GitHub Desktop.

Select an option

Save ifthenelse/0dc2cfe5d15a22d0bb787b76da02d215 to your computer and use it in GitHub Desktop.
Zsh script to generate favicons from an image
#!/usr/bin/env zsh
VERSION="1.0.0"
print_help() {
echo "Usage: $0 <input-image>"
echo ""
echo "Example:"
echo " $0 logo.png"
echo ""
echo "Outputs:"
echo " favicon.ico (16x16, 32x32)"
echo " favicon_128.png (180x180)"
echo " favicon_144.png (144x144)"
echo " favicon_192.png (192x192)"
echo " favicon_384.png (384x384)"
echo " favicon_512.png (512x512)"
}
# flags
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
print_help
exit 0
fi
if [[ "$1" == "-v" || "$1" == "--version" ]]; then
echo "$VERSION"
exit 0
fi
# dependency check
if ! command -v magick >/dev/null 2>&1; then
echo "Error: ImageMagick (magick) not found."
echo "Install with:"
echo " brew install imagemagick"
exit 1
fi
INPUT="$1"
if [[ -z "$INPUT" || ! -f "$INPUT" ]]; then
echo "Error: input file missing or not found."
print_help
exit 1
fi
# ICO (multi-size)
magick "$INPUT" \
-resize 32x32 \
\( -clone 0 -resize 16x16 \) \
favicon.ico
# PNG outputs (contain behavior via default resize)
magick "$INPUT" -resize 180x180 -background none -gravity center -extent 180x180 favicon_128.png
magick "$INPUT" -resize 144x144 -background none -gravity center -extent 144x144 favicon_144.png
magick "$INPUT" -resize 192x192 -background none -gravity center -extent 192x192 favicon_192.png
magick "$INPUT" -resize 384x384 -background none -gravity center -extent 384x384 favicon_384.png
magick "$INPUT" -resize 512x512 -background none -gravity center -extent 512x512 favicon_512.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment