python svg to png

Solutions on MaxInterview for python svg to png by the best coders in the world

showing results for - "python svg to png"
Amelie
06 Mar 2019
1# pip install cairosvg
2import cairosvg
3
4svg_code = """
5    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
6        <circle cx="12" cy="12" r="10"/>
7        <line x1="12" y1="8" x2="12" y2="12"/>
8        <line x1="12" y1="16" x2="12" y2="16"/>
9    </svg>
10"""
11cairosvg.svg2png(bytestring=svg_code,write_to='output.png')
12
13
14cairosvg.svg2pdf(
15	url='image.svg', write_to='image.pdf')
16
17cairosvg.svg2png(
18    url="/path/to/input.svg", write_to="/tmp/output.png")
19
20cairosvg.svg2pdf(
21    file_obj=open("/path/to/input.svg", "rb"), write_to="/tmp/output.pdf")
22
23output = cairosvg.svg2ps(
24    bytestring=open("/path/to/input.svg").read().encode('utf-8'))
25
26# https://cairosvg.org/
27# https://stackoverflow.com/questions/6589358/convert-svg-to-png-in-python