自动化“简化路径”对于 svg 文件(使用 inkscape)
我想自动化 inkscape 命令“简化路径”。具体来说,我想要一个命令行工具,它将 svg 文件作为输入,将“简化路径”应用于图中的所有路径,并保存一个新的(较小的)svg 文件。使用 inkscape 可以吗?有没有一个免费的命令行工具(我使用的是linux)可以完成这项工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新 (2023-06-07):
v1.2 中的命令行再次发生变化。现在它应该类似于(未经测试!):
您可以通过运行以下命令获取所有操作的所有列表:
并选择适合您需求的操作。保存有点棘手,因为它没有在操作中列出。手册上是这么说的:
更新(2021):
由于问题/答案很旧,inkscape 命令行已更改。
另请参阅 Oren Ben-Kiki 或 Pix 答案的评论。
ORIG:
应该可以:
http://tavmjong .free.fr/INKSCAPE/MANUAL/html/CommandLine.html
展示了如何从命令行调用 inkscape 的函数(称为“动词”)。要获取所有动词的列表,请在命令行上调用
inkscape --verb-list
。您正在寻找的是SelectionSimplify
。因此,您必须编写一个小脚本,过滤 svg 中的每个 id,并使用 id 调用 inkscape。像这样的东西(优化所有路径并最后退出 inkscape)
UPDATE (2023-06-07):
Again the command line changed in v1.2. Now it should be something like (untested!):
You can get a list of all list of all actions by running:
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:
UPDATE (2021):
Since the question/answer is quite old the inkscape command line changed.
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 isSelectionSimplify
.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)
从 Fabian 的答案延伸,为了控制简化函数的阈值,我发现我需要制作一个假主目录带有包含我所需阈值的最小首选项文件。这是我刚刚整理的一个简单脚本。
简化.sh:
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:
Inkscape 的替代方案
我使用 SVGO 获得了更好的结果(减少了文件从 2.7 MB 到 350 KB)。
您可以针对单个文件使用此在线服务:https://jakearchibald.github.io/svgomg/
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/