How to automate Inkscape export?

3

Currently I do this in a BAT file:

Inkscape.exe --file "some.svg" --export-png "some_64.png" --export-width 64
Inkscape.exe --file "some.svg" --export-png "some_96.png" --export-width 96
Inkscape.exe --file "some.svg" --export-png "some_128.png" --export-width 128

But that is kind of slow to run Inkscape 3 times in a row and open the same file, plus you have to save the source svg file prior to running the export BAT and make sure the BAT gets the right filename.

So I'm wondering if there is a tool (or plugin) that allows programmatic, or batch, export from Inkscape, something like Export Bitmap dialog, but with scripting support?

Vitaly

Posted 2011-06-10T10:13:09.130

Reputation: 193

I would use Gimp to do the export, as you can batch exports and easily use scripts to change what you need. I created my own batcher the other day for my question : http://gamedev.stackexchange.com/questions/12997/tool-to-convert-textures-to-power-of-two/13286#13286. I can help you out with that if you want.

– None – 2011-06-10T10:29:39.737

Answers

1

An alternative would be to create a rectangle for each export size you want, and put each of them in a separate layer (e.g. named as the export size - size64, size96 etc.).

The trick is that when you select one of those rectangles, and hit export, that object will remember the export properties, e.g. the size of the exported bitmap, aswell as the path. Be sure to stay in the "Selection" tab of the export bitmap dialog.

Make all rectangle layers fully transparent. Note that it is still possible to select such a rectangle both by left-clicking and Ctrl+A:ing if the layer it is in is the active layer.

Once you have defined these export targets/rectangles, you can re-export them once again by selecting[1] all the export rectangles and hitting Ctrl+Shift+E again to get the export dialog. Hit the checkbox "Batch export X objects" and hit Export!

Now to make this process economic, you might want to define a whole array of rectangles for all your graphics, so you have one rectangle for each graphic, in each non-graphic layer.

[1] selecting all export rectangles requires a little trick: in layer dialog lock all non-export-rectangle-layers and then hit Ctrl+A. Voila - all transparent export rectangles selected!

Olof Bjarnason

Posted 2011-06-10T10:13:09.130

Reputation: 943

0

https://inkscape.org/doc/inkscape-man.html#shell

With this parameter, Inkscape will enter an interactive command line shell mode. In this mode, you type in commands at the prompt and Inkscape executes them, without you having to run a new copy of Inkscape for each command. This feature is mostly useful for scripting and server uses: it adds no new capabilities but allows you to improve the speed and memory requirements of any script that repeatedly calls Inkscape to perform command line tasks (such as export or conversions). Each command in shell mode must be a complete valid Inkscape command line but without the Inkscape program name, for example:

    file.svg --export-pdf=file.pdf

Not sure if a Windows batch script is able to communicate interactively. That's not an issue with current scripting languages, e.g. Python.

Inkscape does not seem to be scriptable.
Inkscape Extensions seem to by mostly for generating / modifying / processing the SVG graphics/data, but not for automating the UI functions: https://inkscape.org/develop/extensions/ (see some extensions at https://inkscape.org/gallery/=extension/).

For general automation (e.g. to enter parameters and click the Export button automatically), have a look at https://en.wikipedia.org/wiki/AutoHotkey.

If rendering SVG to images is all that is required, there are other SVG-capable graphics programs/libraries without GUI overhead.

handle

Posted 2011-06-10T10:13:09.130

Reputation: 225