Created
January 5, 2026 18:19
-
-
Save grocky/474113292517f945204db5d903b90582 to your computer and use it in GitHub Desktop.
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 | |
| set -e | |
| # Generate favicon.ico and PNG icons from favicon.svg | |
| # Requires: Inkscape, ImageMagick | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| PUBLIC_DIR="$(cd "$SCRIPT_DIR/../public" && pwd)" | |
| SOURCE_SVG="$PUBLIC_DIR/favicon.svg" | |
| echo "Generating icons from favicon.svg" | |
| echo "==================================" | |
| echo "" | |
| # Check for source SVG | |
| if [ ! -f "$SOURCE_SVG" ]; then | |
| echo "Error: Source file not found: $SOURCE_SVG" | |
| exit 1 | |
| fi | |
| # Check for required tools | |
| if ! command -v inkscape &> /dev/null; then | |
| echo "Error: Inkscape is required but not installed." | |
| echo "Install with: brew install inkscape" | |
| exit 1 | |
| fi | |
| # Check for ImageMagick (prefer magick for v7, fallback to convert for v6) | |
| if command -v magick &> /dev/null; then | |
| IMAGEMAGICK_CMD="magick" | |
| elif command -v convert &> /dev/null; then | |
| IMAGEMAGICK_CMD="convert" | |
| else | |
| echo "Error: ImageMagick is required but not installed." | |
| echo "Install with: brew install imagemagick" | |
| exit 1 | |
| fi | |
| echo "Source: $SOURCE_SVG" | |
| echo "Output: $PUBLIC_DIR" | |
| echo "" | |
| # Define sizes | |
| SIZES=(16 32 192 512) | |
| APPLE_TOUCH_SIZE=180 | |
| # Create temporary directory for intermediate files | |
| TEMP_DIR=$(mktemp -d) | |
| trap "rm -rf $TEMP_DIR" EXIT | |
| echo "Exporting PNG files..." | |
| # Export each size using Inkscape | |
| for size in "${SIZES[@]}"; do | |
| output_file="$PUBLIC_DIR/icon-${size}.png" | |
| echo " Generating icon-${size}.png..." | |
| inkscape "$SOURCE_SVG" \ | |
| --export-type=png \ | |
| --export-filename="$output_file" \ | |
| --export-width="$size" \ | |
| --export-height="$size" \ | |
| 2>/dev/null | |
| done | |
| # Generate apple-touch-icon (180x180) | |
| echo " Generating apple-touch-icon.png (${APPLE_TOUCH_SIZE}x${APPLE_TOUCH_SIZE})..." | |
| inkscape "$SOURCE_SVG" \ | |
| --export-type=png \ | |
| --export-filename="$PUBLIC_DIR/apple-touch-icon.png" \ | |
| --export-width="$APPLE_TOUCH_SIZE" \ | |
| --export-height="$APPLE_TOUCH_SIZE" \ | |
| 2>/dev/null | |
| echo "" | |
| echo "Generating favicon.ico..." | |
| # Create favicon.ico from 16x16 and 32x32 PNGs using ImageMagick | |
| $IMAGEMAGICK_CMD "$PUBLIC_DIR/icon-16.png" "$PUBLIC_DIR/icon-32.png" \ | |
| -colors 256 \ | |
| "$PUBLIC_DIR/favicon.ico" | |
| echo "" | |
| echo "Generated files:" | |
| ls -lh "$PUBLIC_DIR/favicon.ico" "$PUBLIC_DIR/icon-"*.png "$PUBLIC_DIR/apple-touch-icon.png" | |
| echo "" | |
| echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment