Svgo: Option to resize the viewbox to fit the svg content

Created on 20 May 2016  Ā·  7Comments  Ā·  Source: svg/svgo

Would something like this be possible? If you look at the octicons on github, they are cropped to fit the artwork bounds.
I know that illustrator and inkscape have these options, but I was wondering if such a task could be automated using npm scripts.

Most helpful comment

That would be nice addition :+1:

I agree it's indeed seems to be a bit out of scope for svgo, however, from another perspective, it can be named as kind of optimization too.

All 7 comments

It's totally possible. Actually ā€˜transformsWithOnePath’ plugin computes BBox of the path (but for scaling). You need only to translate and resize the image (can be done jusy by amending viewBox). However, the plugin supports only relative coordinates commands (e.g. ā€œlā€ but not ā€œLā€) and the task itself is not a SVGOs purpose.

Yea, it's not really in SVGOs domain. What would be the best way to go about the problem in your opinion?

Developing own SVGO plugin is totally fine I think.

I'll try. Still trying to understand how this all works :) Could use some help.

General information is in ā€œHow it worksā€ doc.

That would be nice addition :+1:

I agree it's indeed seems to be a bit out of scope for svgo, however, from another perspective, it can be named as kind of optimization too.

There is a https://github.com/cncf/svg-autocrop project which does exactly this. It is used a lot in a cloud native computer foundation projects like landscape.cncf.io to automatically crop all svg files via calculating an ideal viewbox.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jwilson8767 picture jwilson8767  Ā·  4Comments

ai picture ai  Ā·  5Comments

bdkjones picture bdkjones  Ā·  3Comments

wuz picture wuz  Ā·  3Comments

mahnunchik picture mahnunchik  Ā·  3Comments