#!/bin/bash
# Generate PNG assets from SVGs for WordPress Plugin Directory
# Requires: rsvg-convert (librsvg2-bin) or Inkscape
#
# Install rsvg-convert:
#   Ubuntu/Debian: sudo apt install librsvg2-bin
#   macOS: brew install librsvg
#
# WordPress SVN assets directory expects these PNG files:
#   icon-128x128.png    - Plugin icon (standard)
#   icon-256x256.png    - Plugin icon (retina)
#   banner-772x250.png  - Plugin banner (standard)
#   banner-1544x500.png - Plugin banner (retina)

set -e
cd "$(dirname "$0")"

if command -v rsvg-convert &> /dev/null; then
    echo "Using rsvg-convert..."
    rsvg-convert -w 128 -h 128 icon.svg -o icon-128x128.png
    rsvg-convert -w 256 -h 256 icon.svg -o icon-256x256.png
    rsvg-convert -w 772 -h 250 banner-772x250.svg -o banner-772x250.png
    rsvg-convert -w 1544 -h 500 banner-1544x500.svg -o banner-1544x500.png
elif command -v inkscape &> /dev/null; then
    echo "Using Inkscape..."
    inkscape icon.svg -w 128 -h 128 -o icon-128x128.png
    inkscape icon.svg -w 256 -h 256 -o icon-256x256.png
    inkscape banner-772x250.svg -w 772 -h 250 -o banner-772x250.png
    inkscape banner-1544x500.svg -w 1544 -h 500 -o banner-1544x500.png
elif command -v convert &> /dev/null; then
    echo "Using ImageMagick..."
    convert -background none -resize 128x128 icon.svg icon-128x128.png
    convert -background none -resize 256x256 icon.svg icon-256x256.png
    convert -background none -resize 772x250 banner-772x250.svg banner-772x250.png
    convert -background none -resize 1544x500 banner-1544x500.svg banner-1544x500.png
else
    echo "Error: No SVG to PNG converter found."
    echo "Install one of: librsvg2-bin, inkscape, or imagemagick"
    exit 1
fi

echo "PNG assets generated successfully:"
ls -la *.png
