8

I'd like to be able to derive new images from a pre-existing image from the command line. To do that, I'd turn on/off specific layers that have portions of the image and then save the resulting image to a file. However, while I can see a number of commands listed in the help to manipulate layers, I don't see any that would allow one to select a specific one and turn it on/off.

hoijui
  • 3,615
  • 2
  • 33
  • 41
Brian
  • 372
  • 1
  • 4
  • 12
  • While not being true at time of posting, there is now this [related question](https://graphicdesign.stackexchange.com/q/54615/inkscape-scripting-how-to-show-hide-a-layer-and-export) on a more specific StackExchange site. – sampi Feb 26 '22 at 11:28

3 Answers3

7

If what you want to do can be achieved by deleting a few unwanted elements by their id (say, layer17 and layer4711), you can do it this way:

inkscape image.svg \
  --select=layer17   --verb=EditDelete \
  --select=layer4711 --verb=EditDelete \
  --verb=FileSave --verb=FileClose

Note that this will overwrite image.svg with the result, so if you're scripting this, be sure to work on a copy rather than your originals.

ecmanaut
  • 5,030
  • 2
  • 44
  • 66
  • This doesn't work for me (inkscape 0.91). I am on Windows, could this be the problem? – René Nyffenegger Aug 20 '15 at 08:29
  • It likely needs adapting for windows too; the above format was from a mac or similarly unix style environment (likely made better still with Skela's tips in another answer). If you discover how to adapt it to Windows, do tell – it'll help someone else in your situation. – ecmanaut Aug 20 '15 at 17:17
  • 1
    note that here you need to use the layer *id* (which you can see under "Edit -> XML Editor ..."), not the layer *name* (which is what you primarily see in the Inkscape GUI) – hoijui Aug 10 '17 at 10:17
3
inkscape image.svg --export-id-only --export-id=layer17 --export-png=image.png --export-width=100 --export-height=100

On a Mac you might have to do:

/Applications/Inkscape.app/Contents/Resources/bin/inkscape --without-gui --file=image.svg --export-id-only --export-id=layer17 --export-png=image.png --export-width=100 --export-height=100
Skela
  • 884
  • 10
  • 18
  • sadly, this only allows to select a single layer per generated image – hoijui Aug 10 '17 at 10:12
  • you could easily have it export each layer you want to separate files, and then you use something like imageMagick to combine them – Skela Aug 25 '17 at 19:27
1

I've written an Inkscape extension for work like this. It outputs one file for each option layer found. It will also show various layer combinations as needed. Scriptable as well. I call it the SLiCk Layer Combinator:

https://github.com/juanitogan/slick

juanitogan
  • 1,698
  • 1
  • 22
  • 37