Jimmac’s post got me thinking. His script did the job for a single icon. Why not improve upon it to allow multiple icons sharing a single SVG file? Immediately decided to give it a go and after a few iterations the result works as follows:
- You start by creating a template SVG.
- For each icon (not size) you create a layer
and set its name to.context/icon-name
. You can use a different syntax but it has to contain at least one slash. The rest of the layers are treated as drawing aids - For each layer you create a sublayer and give it a name starting with
plate
. Inkscape requires you to have distinct layer labels so a simpleplate
won’t do for multiple icons but you are free to use names such asplate for foo.
- The plate consists of a set of rectangles. Each rectangle will result in a separate PNG and the size is taken verbatim from the rectangles (so make sure you don’t end up with ten decimal places in width or height).
- The plate also needs two text objects: one with label set to
context
and one with label set toicon-name
. The text you put there is used to create the directory structure. - Save your template to a directory called
svg
. Make sure you hide the plate layers before saving. - Download the Split Icons script.
- Run the script. If you pass a path (or several paths), it will only process the files from the command line. If you don’t pass anything, it will process the whole
svg
directory. - Draw art!
Here’s a template example.
PS: b.g.o upload sucks. It will only accept .gz
files and then will strip the dot from the original extension.
Update: updated the script to handle the new format invented by jimmac. See the example above for details.
Thanks for the suggestions. I fear the layer dock is not prominent enough and you have a disconnect between what’s on the canvas and what’s on the list, thus I am likely to screw up mispelling something.
I ended up using your idea except putting the context/name editing directly on the canvas. It’s up my face, maybe the chance to screw up is smaller.
Updated the script 🙂