#!/usr/bin/env bash # Convert an SVG file to a square PNG using whichever converter is available. # Tries, in order: rsvg-convert, inkscape, magick, convert. # Usage: svg2png.sh [size] set -e in="$1" out="$2" size="${3:-256}" [ -f "$in" ] || { echo "svg2png: input not found: $in" >&2; exit 1; } if command -v rsvg-convert >/dev/null 2>&1; then rsvg-convert -w "$size" -h "$size" -o "$out" "$in" && exit 0 fi if command -v inkscape >/dev/null 2>&1; then if inkscape --version 2>/dev/null | grep -Eq 'Inkscape 0\.'; then inkscape -z "$in" -e "$out" -w "$size" -h "$size" && exit 0 fi inkscape "$in" --export-type=png --export-filename="$out" -w "$size" -h "$size" && exit 0 fi if command -v magick >/dev/null 2>&1; then magick -background none "$in" -resize "${size}x${size}" "$out" && exit 0 fi if command -v convert >/dev/null 2>&1; then convert -background none "$in" -resize "${size}x${size}" "$out" && exit 0 fi echo "svg2png: no SVG converter found (install librsvg, inkscape or imagemagick)" >&2 exit 1