Created
November 15, 2024 09:06
-
-
Save MiPnamic/2a1d330721d5314af27cbae3de5c2718 to your computer and use it in GitHub Desktop.
ImageMagick bash script for creating a favicon.ico embedding multiple version of a starting PNG image
This file contains hidden or 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 | |
| # Check if ImageMagick is installed | |
| if ! command -v magick &>/dev/null; then | |
| echo "Error: ImageMagick not installed." | |
| exit 1 | |
| fi | |
| # Check if the input file is provided | |
| if [ -z "$1" ]; then | |
| echo "Usage: $0 <path_to_image>" | |
| echo "Error: specify a PNG input image." | |
| exit 1 | |
| fi | |
| # Check if the input file exists | |
| if [ ! -f "$1" ]; then | |
| echo "Error: file '$1' does not exits." | |
| exit 1 | |
| fi | |
| INPUT_FILE="$1" | |
| OUTPUT_DIR="tmp_fav" | |
| mkdir -p "$OUTPUT_DIR" | |
| cp "$INPUT_FILE" "$OUTPUT_DIR/favicon.png" | |
| cd "$OUTPUT_DIR" || exit | |
| # Resize images | |
| echo "Resizing..." | |
| magick favicon.png -resize 16x16 favicon-16x16.png | |
| magick favicon.png -resize 32x32 favicon-32x32.png | |
| magick favicon.png -resize 48x48 favicon-48x48.png | |
| magick favicon.png -resize 64x64 favicon-64x64.png | |
| magick favicon.png -resize 180x180 favicon-180x180.png | |
| # Create the favicon.ico file | |
| echo "Creating favicon.ico..." | |
| magick favicon-16x16.png favicon-32x32.png favicon-48x48.png favicon-64x64.png favicon-180x180.png favicon.ico | |
| cp favicon.ico .. | |
| cd .. | |
| # Clean up: remove the temporary directory | |
| echo "Cleanup..." | |
| rm -rf "$OUTPUT_DIR" | |
| echo "Favicon.ico created." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment