In python, to convert svg to png, we can use svglib or cairosvg library, however, cairosvg need other toolkit to support. In this tutorial, we will use svglib to convert a svg to png.
Install svglib
pip install svglib
Import library
from svglib.svglib import svg2rlg from reportlab.graphics import renderPM
Load svg file
drawing = svg2rlg("home.svg")
Convert svg to png
renderPM.drawToFile(drawing, "file.png", fmt="PNG")
Then, we have converted svg to png file successfully.
Then you can convert png to other image format, such as jpg, webp, bmp with pillow.
Best Practice to Python Convert PNG to WebP with Pillow – Python Pillow Tutorial