Closed Dreamsorcerer closed 3 years ago
There is a workable approach without modifiying the lib, too. (this should be in the readme, how to use the img
presented in the example)
import io
f = io.BytesIO()
img.save(f)
f.getvalue() ==> b'<?xml ....'
You can use the code in this PR without modifying the lib anyway..
ET.tostring(img._img)
SVGs are particularly useful to have in string format, which can be output directly into HTML etc.
It took me far to long to figure out how to do this, so hopefully this will save other people some time.
As a side note, the SVGPathImage in the _write() method (which I've based this code on), appends the path code to the image element. Wouldn't this mess up the image if the save() method is called twice? Edit: Seems to be a fix #137