thx / resvg-js

A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs.
https://resvg-js.vercel.app/
Mozilla Public License 2.0
1.57k stars 57 forks source link

Pixelated png <image> #327

Closed martinklepsch closed 7 months ago

martinklepsch commented 7 months ago

Hey there & thanks for the great lib!

I've been noticing some pixelated images when PNG images are downscaled for their <image> container.

In the screenshot below, note how the resvg-js output looks slightly more pixelated than what resvg's viewsvg app shows.

Do you have any ideas why this could be? Should I attempt to downscale images before passing them to resvg-js?

Screenshot 2024-04-11 at 18 14 37

(The raw svg for the screenshot can be found in this gist.)

yisibl commented 7 months ago

In your SVG, the actual size of the first image (Logo) is 1200 × 630, so of course you need to set it to a larger size to display it more clearly. When your screen devicePixelRatio is greater than 1, you need to set the width of the output png to devicePixelRatio * 1200.

Many parts of the image are blank, you should crop out the blank parts to make them smaller in width and height so that the rendering will be faster as well.

Here is the actual PNG after I converted your base64 image:

logo output2
martinklepsch commented 7 months ago

I was actually more referring to the pixelation of the image on the right. I was thinking that resvg should downscale it for the provided width but the pixelation you can see for the text in the image on the right is different in resvg-js than it is in viewsvg.

Screenshot 2024-04-18 at 11 21 34

Hope this makes sense