如何将 SVG 图像裁剪到矢量图形元素的边界框

发布于 2025-01-17 07:18:13 字数 350 浏览 1 评论 0原文

我这里有一个 SVG 图像在此处输入图片描述是用“空白”生成的,即只有左上角是图片内容,其余都是空白。我认为完全可能有一种自动方式将图像大小裁剪到对象的边界框 - 至少对于像 rsvg 这样的一些 svg 工具来说是这样。但是我无法找到“命令行技巧”,等等。

我想在命令行上执行此操作(即作为构建脚本的一部分)

原则上我会对同一问题的解决方案感兴趣,但是也适用于基于像素的格式,例如 PNG。

I have a SVG image hereenter image description herewhich is generated with 'empty space', i.e. only in the top-left corner is image content, whereas the rest is blank. I think it should be trivially possible to have an automated way to crop the image size to the bounding box of the objects - at least for some svg tooling like rsvg. However I am unable to find the 'command line trick' for this, etc.

I would like to do this on the command line (i.e. as part of a build script)

In principle I would be interested in a solution to the same problem but for pixel-based formats such as PNG as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窝囊感情。 2025-01-24 07:18:13

rsvg 没有解决此问题的命令行实用程序,但 Inkscape 在其非 GUI 模式下具有:

inkscape -o cropped.svg -D source.svg

将文件裁剪为文档所有对象的边界框。有关 inkscape 命令行选项的完整文档,请参阅 手册页。特别注意用于批量处理多个图像的 --shell 模式。

对于基于像素的格式,有 imagemagick -trim 选项:

convert source.png -trim +repage cropped.png

rsvg does not have command line utilities for this problem, but Inkscape in its non-GUI mode has:

inkscape -o cropped.svg -D source.svg

will crop the file to the bounding box of all objects of the document. See the man page for a full documentation of the inkscape command line options. Especially note the --shell mode for batch processing multiple images.

For pixel-based formats there is the imagemagick -trim option:

convert source.png -trim +repage cropped.png
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文