Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svgwrite - How to enable write/add other objects as layers of an existing .svg file

Tags:

python

svg

I have an svg file and I want to insert other svg object inside this existent.

import svgwrite

dwg = svgwrite.Drawing('model.svg')
square = dwg.add(dwg.rect(20,20),(80,80), fill='blue'))
dwg.save()

it returns a new file with this shape ignoring my previous file. How could I write this?

Thank's

like image 329
arnaldo Avatar asked Dec 14 '22 23:12

arnaldo


1 Answers

I found a module to do that

import svgutils.transform as st

template = st.fromfile('template.svg')
second_svg = st.fromfile('second.svg')
template.append(second_svg)
template.save('merged.svg')

I hope that works for you too.

like image 119
arnaldo Avatar answered Dec 29 '22 00:12

arnaldo