linebender / resvg

An SVG rendering library.
Apache License 2.0
2.84k stars 229 forks source link

Separate options for rendered SVG size and total image canvas size #825

Open ahmetsait opened 1 month ago

ahmetsait commented 1 month ago

Currently we are able to provide render size via --width and --height options but there is no way to produce a padded png from a non-padded svg. My use case revolves around generating a bunch of website favicons from an svg file. At first I tried to create another padded svg file which references the original file with <use xlink:href="favicon.svg#id" /> to avoid duplication but turns out external file references are not supported yet. Then I tried to see if it's possible to somehow specify render and final image sizes separately but looks like it's also not possible currently.

Feature Request Introduce --render-width and --render-height to specify what size the svg will be rendered. If the render size is smaller then image size, it is centered. If the render size is bigger, it is centered but also cropped.

We can think about introducing a --scale-mode=(scale,fill,stretch,none) option later on if necessary.

RazrFalcon commented 1 month ago

The problem with this feature is that everyone want a slightly different behavior and it would be somewhat hard to handle all cases.

Will see.

ahmetsait commented 1 month ago

Thinking about this a bit more, I think the following CLI options would satisfy everyone's needs:

What do you think? I don't know how hard it is to implement --scale-mode=stretch, I added it for the sake of completeness so feel free to ignore it.

Btw resvg is already pretty awesome as is so thanks for this great piece of software. I would love to help out with PRs but I'm no Rust programmer... yet.

RazrFalcon commented 1 month ago

What do you think?

Hard to say without trying. Maybe someone would be interested in sending a PR.