When using together with inkscape, export svg images via “File” -> “Save As” and select “Plain SVG” as file type.
Images are processed in five steps
fill
andstroke
attributes stored instyle
are extracted and stored directly on the element- Colors are converted to lowercase, named colors (e.g. “red”) are converted to hex colors.
- All fill and stroke colors appearing in the image are collected into a list
- For each color, a copy of the image is created
and all elements with a different color are removed.
The image is then saved in a file named
color_#abcdef.svg
where#abcdef
is the color used. - If an element has different
fill
andstroke
colors, when exporting the image for one of them, the other is set tonone
.
Usage: python3 svg.py input.svg
- list colors
- remove color
- remove everything but one color
- split colors into layers
I copied the list of named colors from the Inkscape extension python modules.