|
4 years ago | |
---|---|---|
.. | ||
README.md | 4 years ago |
Inkscape has a bunch of useful CLI command parameters that can be used to apply changes to SVGs (or any format it can open) directly from the command line. e.g.
inkscape -f FILENAME.svg -e FILENAME.png
This opens the svg file and exports it to a destination png. This is great for day to day light functions but very useful when you want to batch process files. e.g. If you have lots of SVGs and you want to export to PNGs quickly.
There are "verbs" that can be run from cli. "verbs" are just some names given to all the Menu commands in Inkscape. You can think of them as "actions". You need these IDs when you want to run them from the cli. You can get a list of these with:
inkscape --verb-list
The syntax is easy:
inkscape ... --verb <verb name here>
We can run something like this to convert all the strokes to path in an SVG file:
inkscape -f file.svg --verb EditSelectAll --verb StrokeToPath --verb FileSave --verb FileQuit
Here, -f
opens the file in inkscape, --verb EditSelectAll
selects every object in the file, --verb StrokeToPath
converts all selected objects from stroke to path, --verb FileSave
saves the file, --verb FileQuit
quits Inkscape.
(a) One of the problems is that you can't use Inkscape without GUI (headlessly) when you use verbs because of a bug. There is a workaround until the bug is fixed. We can use xvfb-run
to run inkscape headlessly. It creates a virtual framebuffer X display server that runs the GUI virtually without needing to show it on-screen.
(b) Another problem is that you can't create a file with inkscape. This does not work even if you use --verb FileSaveAs somefile.svg
. So you'll have to copy the source file and then edit it in place.
# Workaround for save as, because inkscape can't create files itself. ...(b)
cp original.svg new.svg
# Workaround for not being able to use Inkscape headlessly. ...(a)
xvfb-run inkscape -f new.svg --verb EditSelectAll --verb StrokeToPath --verb FileSave --verb FileQuit
One thing is that you should always add --verb FileQuit
at the end when using xvfb-run
because otherwise it will keep running in the background.
Ref: