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

View file

@ -5,10 +5,12 @@ cd "$(dirname "$0")"
VERSION=$(node -p "require('./package.json').version") VERSION=$(node -p "require('./package.json').version")
OUT="build/PLGL-$VERSION.tar.gz" OUT="build/PLGL-$VERSION.tar.gz"
bash tools/svg2png.sh renderer/plgl.svg renderer/plgl.png 256
rm -rf build/dist rm -rf build/dist
mkdir -p build/dist/PLGL build/files mkdir -p build/dist/PLGL build/files
cp -r src renderer files package.json build/dist/PLGL/ cp -r src renderer tools files package.json build/dist/PLGL/
cp -r files/translations build/files/ 2>/dev/null || true cp -r files/translations build/files/ 2>/dev/null || true
if [ ! -d node_modules/electron/dist ]; then if [ ! -d node_modules/electron/dist ]; then
@ -24,6 +26,7 @@ cat > build/dist/PLGL/run.sh << 'EOF'
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
cd "$(dirname "$0")" cd "$(dirname "$0")"
bash tools/svg2png.sh renderer/plgl.svg renderer/plgl.png 256
exec ./node_modules/electron/dist/electron . "$@" exec ./node_modules/electron/dist/electron . "$@"
EOF EOF
chmod +x build/dist/PLGL/run.sh chmod +x build/dist/PLGL/run.sh

2
run.sh
View file

@ -7,6 +7,8 @@ if [ ! -d node_modules ]; then
npm install npm install
fi fi
bash tools/svg2png.sh renderer/plgl.svg renderer/plgl.png 256
mkdir -p build/files mkdir -p build/files
cp -r files/translations build/files/ 2>/dev/null || true cp -r files/translations build/files/ 2>/dev/null || true

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