svginkscape

Automatizing 'simplify path' for a svg-file (using inkscape)


I would like to automatize the inkscape command "simplify path". Concretely, I would like a command line tool which takes a svg-file as input, applies "simplify path" to all paths in the figure and saves a new (smaller) svg-file. Is this possible using inkscape? Is there a free command line tool (I'm using linux) which does the job?


Solution

  • UPDATE (2023-06-07):

    Again the command line changed in v1.2. Now it should be something like (untested!):

    inkscape backpacks-svgrepo-com.svg --batch-process --actions='select-all;path-simplify;export-plain-svg'
    

    You can get a list of all list of all actions by running:

    inkscape --action-list
    

    and chose those fitting to your needs. Saving is a bit more tricky as it's not listed in the actions. The manual says something like:

    In addition, there are actions matching all export options (to use them, simply remove the prefix '--' in front of the option and replace '=' with ':')


    UPDATE (2021):

    Since the question/answer is quite old the inkscape command line changed.

    inkscape file.svg --batch-process --actions='EditSelectAll;SelectionSimplify;FileSave;FileClose'
    

    Also see comment of Oren Ben-Kiki or Pix answer.

    ORIG:

    Should be possible:

    http://tavmjong.free.fr/INKSCAPE/MANUAL/html/CommandLine.html

    shows how to call functions of inkscape (called "verbs") from the command line. To get a list of all verbs call inkscape --verb-list on commandline. What you are looking for is SelectionSimplify.

    Therefore you have to write a small script that is filtering every id out of the svg and is calling inkscape with the ids. Something like this (optimize all pathes and quit from inkscape at the end)

    inkscape filename.svg --verb=EditSelectAll --verb=SelectionSimplify --verb=FileSave --verb=FileClose --verb=FileQuit