#!/bin/bash
# Generate favicon.ico from logo.png using ImageMagick

# Check if ImageMagick is installed
if ! command -v convert &> /dev/null; then
    echo "Error: ImageMagick is not installed. Please install it first:"
    echo "  Ubuntu/Debian: sudo apt install imagemagick"
    echo "  macOS: brew install imagemagick"
    echo "  CentOS/RHEL: sudo yum install ImageMagick"
    exit 1
fi

# Check if logo.png exists
if [ ! -f "src/img/logo.png" ]; then
    echo "Error: src/img/logo.png not found!"
    exit 1
fi

echo "Generating favicon.ico from logo.png..."

# Generate favicon with multiple sizes (16x16, 32x32, 48x48)
# The -background transparent ensures transparency is preserved
# The -flatten combines all layers
convert src/img/logo.png \
    -background transparent \
    \( -clone 0 -resize 16x16 \) \
    \( -clone 0 -resize 32x32 \) \
    \( -clone 0 -resize 48x48 \) \
    -delete 0 \
    -alpha on \
    src/img/favicon.ico

if [ $? -eq 0 ]; then
    echo "✅ Successfully generated src/img/favicon.ico"
    echo "Favicon sizes included: 16x16, 32x32, 48x48"
else
    echo "❌ Failed to generate favicon"
    exit 1
fi
