|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# gen-icons.sh - Generate all application icons from SVG source |
| 4 | +# |
| 5 | +# This script regenerates all PNG icons in ui/icons/hicolor/ from the SVG source |
| 6 | +# with transparent backgrounds for proper display on various desktop themes. |
| 7 | +# |
| 8 | +# Usage: ./scripts/gen-icons.sh |
| 9 | +# |
| 10 | + |
| 11 | +set -e |
| 12 | + |
| 13 | +# Colors for output |
| 14 | +RED='\033[0;31m' |
| 15 | +GREEN='\033[0;32m' |
| 16 | +YELLOW='\033[1;33m' |
| 17 | +NC='\033[0m' # No Color |
| 18 | + |
| 19 | +# Check if we're in the right directory |
| 20 | +if [[ ! -f "ui/icons/io.github.rubiojr.whereami.svg" ]]; then |
| 21 | + echo -e "${RED}Error: SVG source file not found. Please run from project root.${NC}" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Check if ImageMagick is available |
| 26 | +if ! command -v magick &> /dev/null; then |
| 27 | + echo -e "${RED}Error: ImageMagick 'magick' command not found. Please install ImageMagick.${NC}" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +SVG_SOURCE="ui/icons/io.github.rubiojr.whereami.svg" |
| 32 | +ICON_NAME="io.github.rubiojr.whereami.png" |
| 33 | + |
| 34 | +echo -e "${GREEN}Generating icons from ${SVG_SOURCE}...${NC}" |
| 35 | +echo |
| 36 | + |
| 37 | +# Standard sizes (1x) |
| 38 | +declare -a SIZES=("16" "22" "24" "32" "48" "64" "128" "256" "512") |
| 39 | + |
| 40 | +echo -e "${YELLOW}Generating standard icons...${NC}" |
| 41 | +for size in "${SIZES[@]}"; do |
| 42 | + target_dir="ui/icons/hicolor/${size}x${size}/apps" |
| 43 | + target_file="${target_dir}/${ICON_NAME}" |
| 44 | + |
| 45 | + echo " ${size}x${size} -> ${target_file}" |
| 46 | + magick "${SVG_SOURCE}" -background transparent -resize "${size}x${size}" "${target_file}" |
| 47 | +done |
| 48 | + |
| 49 | +echo |
| 50 | + |
| 51 | +# Retina sizes (@2) |
| 52 | +declare -a RETINA_BASE_SIZES=("16" "24" "32" "48" "64" "128" "256") |
| 53 | + |
| 54 | +echo -e "${YELLOW}Generating retina (@2) icons...${NC}" |
| 55 | +for base_size in "${RETINA_BASE_SIZES[@]}"; do |
| 56 | + # Calculate actual pixel size (double the base size) |
| 57 | + actual_size=$((base_size * 2)) |
| 58 | + |
| 59 | + target_dir="ui/icons/hicolor/${base_size}x${base_size}@2/apps" |
| 60 | + target_file="${target_dir}/${ICON_NAME}" |
| 61 | + |
| 62 | + echo " ${base_size}x${base_size}@2 (${actual_size}x${actual_size}) -> ${target_file}" |
| 63 | + magick "${SVG_SOURCE}" -background transparent -resize "${actual_size}x${actual_size}" "${target_file}" |
| 64 | +done |
| 65 | + |
| 66 | +echo |
| 67 | +echo -e "${GREEN}Icon generation complete!${NC}" |
| 68 | +echo |
| 69 | +echo "Generated icons:" |
| 70 | +find ui/icons/hicolor -name "*.png" | sort | while read -r icon; do |
| 71 | + size=$(identify "$icon" | awk '{print $3}') |
| 72 | + file_size=$(du -h "$icon" | awk '{print $1}') |
| 73 | + echo " $icon (${size}, ${file_size})" |
| 74 | +done |
| 75 | + |
| 76 | +echo |
| 77 | +echo -e "${GREEN}All icons regenerated successfully with transparent backgrounds.${NC}" |
0 commit comments