The content of this article is about how to use python to convert svg to png (code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Install cairosvg
Direct installation will cause errors and you need to install dependencies:
sudo apt install python3-lxml sudo apt install python3-dev sudo apt install libffi-dev sudo apt install libcairo2
pip3 install cairosvg
2. Run
In command-line:
$ cairosvg image.svg -o image.png
Import python3 and run:
$ python3 >>> import cairosvg >>> cairosvg.svg2pdf(url='image.svg', write_to='image.pdf')
Related recommendations:
Python implements code sharing for batch conversion of SVG format into png and pdf formats
Use the imagick library to convert PDF to PNG format PHP code
The above is the detailed content of How to use python to convert svg to png (code). For more information, please follow other related articles on the PHP Chinese website!