linebender / resvg

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

Enforce width/height arguments to be respected #779

Open condemil opened 5 months ago

condemil commented 5 months ago

Use-case: The SVG icon has size 20x30, the online service expects uploaded icon to be PNG with size 64x64px.

Current behavior: The width/height arguments is not respected and work more like a recommendation:

$ resvg --width 64 --height 64 in.svg out.png
$ file out.png
out.png: PNG image data, 43 x 64, 8-bit/color RGBA, non-interlaced

Expected result: The width/height arguments define exact image size. Icon is centered in the resulted image.

Example:

<svg width="20" height="30" viewBox="0 0 20 30" xmlns="http://www.w3.org/2000/svg">
  <circle cx="10" cy="15" r="5" fill="tomato"/>
</svg>
RazrFalcon commented 5 months ago

--width/--height are not recommendations, they define the maximum size preserving the aspect ratio.

What output do you expect? Cropped image? Stretched image? Centered image?

condemil commented 5 months ago

Centered image, not cropped, not stretched. Just as you see it originally when open SVG file. I think it makes sense if you want to use the icon as avatar, or app icon for mobile apps. Or on your website as favicon / icon in manifest.json (android specific favicon).

RazrFalcon commented 5 months ago

Ok, will take a look.

Vasilich commented 5 months ago

But please leave the possibility to keep current behaviour - to use given size as maximum without adding empty space to the resulting PNG. There are also use cases for it.

condemil commented 5 months ago

@Vasilich Depends on use-case it may be that you only need to specify either --width or --height, but not both, then it should work as you mentioned.