1

I have an SVG with multiple layers and I need to generate different png/jpeg files containting all possible combinations of certain layers. Is there a way to do this? I thought it might be possible to do this using the shell command line (I'm using Ubuntu 18.04), by creating a code that first opens the SVG file, shows/hides certain layers and then exports it to png/jpeg, but I don't know how to do this.

2
  • You could use Inkscape to open an SVG, and hide specific layers/objects, and export as PNG. Inkscape is free, Open Source, and works on Linux, Windows, and Mac.
    – Billy Kerr
    Apr 2 at 21:14
  • I don't know how layers are organized in the SVG file, but since it is an XML-format, this should be possible, maybe pretty easy. You should create a few simple test files with enough content, to make it obvious, whether your combinations work or not and either work on the files with something like xmlstarlet or maybe even with a tool like sed. The latter isn*t specialized on XML at all, but is more general about text patterns and can delete blocks of code, here for instance layers. But I don't have the time to try it for you. Apr 24 at 7:50
0

I do believe you can achieve this via the command line with the use of Inkscape's actions and verbs. The official documentation on this is a little sparse but I found this page which has more info https://how-to.fandom.com/wiki/How_to_use_Inkscape_in_commandline_mode. If you click on the verb list you can see there's a DeleteLayer verb. You would need to use a scripting language like bash or python to collect a layer list and iterate through the possibilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.