Automatizing 'simplify path' for a svg

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?


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:

inkscape filename.svg --select=pathID --verb=SelectionSimplify --verb=FileSave --verb=FileClose

I don't know if you can chain the call with all IDs that you have to call inkscape just once for every SVG


Extending from Fabian's answer, to control the threshold of the simplification function, I found I needed to make a fake home directory with a minimal preferences file containing my desired threshold. Here is a simple script I just put together.

simplify.sh:

#!/bin/bash
FILENAME=$1
THRESHOLD=$2
FAKEHOME=$(mktemp -d)
mkdir -p $FAKEHOME/.config/inkscape
cat > $FAKEHOME/.config/inkscape/preferences.xml <<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<inkscape
  xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
  version="1">
  <group
    id="options">
    <group
      id="simplifythreshold"
      value="${THRESHOLD}" />
  </group>
</inkscape>
EOF
HOME=$FAKEHOME inkscape $FILENAME --verb=EditSelectAll --verb=SelectionSimplify --verb=FileSave --verb=FileClose
#rm -rf $FAKEHOME

Alternative to Inkscape

I've got much better results using SVGO (reduced a file from 2.7 MB to 350 KB).

You may use this online service for individual files: https://jakearchibald.github.io/svgomg/

链接地址: http://www.djcxy.com/p/95834.html

上一篇: 将SVG多边形转换为路径

下一篇: 为svg自动化“简化路径”