Search code examples
javascriptimagesvgpngsharp

svg straight lines curved after converting to raster format (png, jpg) Sharpjs


EDIT: https://github.com/lovell/sharp/issues/1421 Use density option

I am converting this svg: https://www.svgviewer.dev/s/fEKKksfU, to png using Sharp.js but it always comes out looking wonky. Here is how I convert it:

sharp(Buffer.from(`SVG HERE`)).png()

and here is the result:

result image

It does not look like the original SVG at all. I am not sure if this is a limitation of going from svg to raster but I know its not supposed to look like the final image. Thank you in advance.

SVG to PNG using Sharp.js does not come out like the original SVG. Lines are wonky and curved.


Solution

  • I seems using the density option mitigates this effect.

    sharp(Buffer.from(`SVG HERE`), {density: 500}).png()