4

I am utilizing svglib and report lab to convert an SVG file to a PNG file.

renderPM.drawToFile(drawing, png_file_path, fmt="PNG", configPIL={'transparent': None})

And it works to convert the file, unfortunately the background of the image is not transparent.

I have tried adding a colour to the transparent attribute of the configPIL and making it transparent that way, but it seems to not affect the background at all.

How can I convert from SVG to PNG with a transparent background using python?

martineau
  • 119,623
  • 25
  • 170
  • 301
DjangoBlockchain
  • 534
  • 2
  • 17
  • 3
    https://github.com/deeplook/svglib/issues/171#issuecomment-457604019 – Sphinxxx Aug 20 '20 at 21:21
  • Check out https://cairosvg.org/documentation/ – Manuel Alves Mar 22 '21 at 18:20
  • I found a workaround by rendering to pdf first with `svglib` and then using `pymupdf` which doesn't need any external libraries as it comes with precompiled wheels. [See my stackoverflow answer here](https://stackoverflow.com/a/74164750/1506569) – M4a1x Oct 22 '22 at 15:41

0 Answers0