auto svg to png

This commit is contained in:
olcxja 2026-09-25 19:46:58 +02:00
commit e017187af5
3 changed files with 39 additions and 1 deletions

33
tools/svg2png.sh Normal file
View file

@ -0,0 +1,33 @@
#!/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 <input.svg> <output.png> [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