简体   繁体   English

如何裁剪 svg?

[英]How to crop svg?

I have an super large svg background and some elements are rendered on top of the background.我有一个超大的 svg 背景,一些元素呈现在背景之上。 I then want to crop the svg such that it fits the elements in the foreground and the background is cropped.然后我想裁剪 svg 以使其适合前景中的元素并裁剪背景。 Is this possible?这可能吗? I am using svg.js but I could not find a build in function for that.我正在使用 svg.js,但我找不到为此构建的函数。 Is it even possible to crop an SVG?甚至可以裁剪 SVG 吗?

Try尝试

convert -crop 100x100+200+150 -scale 1000x750 current-temps.svg

Requires imagemagick to be installed but it's in most distributions' repositories.需要安装imagemagick ,但它在大多数发行版的存储库中。

I managed to solve this issue by the viewbox attribute as mentioned by a comment.正如评论中提到的,我设法通过 viewbox 属性解决了这个问题。 Google did not give me any results for cropping svg or the other terminology I used before posting this question.在发布此问题之前,谷歌没有给我裁剪 svg 或我使用的其他术语的任何结果。 If you have the same issue, know that viewbox can "crop" the svg.如果您有同样的问题,请知道 viewbox 可以“裁剪”svg。 The elements are still their full size but the "zoom" and "pan" of what you can see is adjusted.这些元素仍然是它们的完整大小,但您可以看到的“缩放”和“平移”已调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM