Home > Backend Development > Python Tutorial > How to use python to convert svg to png (code)

How to use python to convert svg to png (code)

不言
Release: 2018-09-08 16:50:58
Original
8189 people have browsed it

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
Copy after login

pip3 install cairosvg

2. Run

In command-line:

$ cairosvg image.svg -o image.png
Copy after login

Import python3 and run:

$ python3
>>> import cairosvg
>>> cairosvg.svg2pdf(url='image.svg', write_to='image.pdf')
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template