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

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

不言
不言Original
2018-09-08 16:50:588120browse

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!

Statement:
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

Related articles

See more