How to Batch-export layers of Inkscape-generated SVG-file to Bitmap for sprites?

Batch -export means that I may need to add certain transformations such as anti-alias, contrast-fixes and resizing. SVG here means I am using Inkscape. One layer here is a sprite. I currently export each layer individually to bitmap, File > Export Bitmap — but it is time-consuming.

enter image description here

  1. Is there some way to programmatically batch-export layers from SVG-file?

  2. Or does there exist some batch-export-button in Inkscape?

  3. I specially need the same custom area for each sprite, the same as clicking many times the menus but it is stupid — perhaps some macro for this?

Answer

You can use the commandline to export all layers. First, so see how many or which layers we have, with --query-all or -S:

$ inkscape --query-all presentation.svg | grep layer | awk -F, '{print $1}'
layer1
layer2
layer3

With the id (exakt name) of the layer, you can now export it with --export-id=ID or -i and -j, --export-id-only

$ inkscape presentation.svg -i layer1 -j -C --export-png=layer1.png

-C, --export-area-page defines the exported area (full page, as defined in document properties). You can also use --export-ps, --export-pdf, --export-eps and some other.


To automate it, you can generate a command list:

$ for id in `seq 1 15`; do echo "presentation.svg -jC -i layer$id -e layer$id.png"; done
presentation.svg -jC -i layer1 -e layer1.png
presentation.svg -jC -i layer2 -e layer2.png
presentation.svg -jC -i layer3 -e layer3.png

When you save this in a file (here commands.txt), you can invoke inkscape like this:

$ inkscape --shell < commands.txt

do execute all listed commands.

Attribution
Source : Link , Question Author : hhh , Answer Author : sebix

Leave a Comment