Answers for "python save svg"

3

python svg to png

# pip install cairosvg
import cairosvg

svg_code = """
    <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">
        <circle cx="12" cy="12" r="10"/>
        <line x1="12" y1="8" x2="12" y2="12"/>
        <line x1="12" y1="16" x2="12" y2="16"/>
    </svg>
"""
cairosvg.svg2png(bytestring=svg_code,write_to='output.png')


cairosvg.svg2pdf(
	url='image.svg', write_to='image.pdf')

cairosvg.svg2png(
    url="/path/to/input.svg", write_to="/tmp/output.png")

cairosvg.svg2pdf(
    file_obj=open("/path/to/input.svg", "rb"), write_to="/tmp/output.pdf")

output = cairosvg.svg2ps(
    bytestring=open("/path/to/input.svg").read().encode('utf-8'))

# https://cairosvg.org/
# https://stackoverflow.com/questions/6589358/convert-svg-to-png-in-python
Posted by: Guest on July-07-2021

Python Answers by Framework

Browse Popular Code Answers by Language