diff --git a/manimlib/mobject/svg/svg_mobject.py b/manimlib/mobject/svg/svg_mobject.py index 6476cd95..fa2286cf 100644 --- a/manimlib/mobject/svg/svg_mobject.py +++ b/manimlib/mobject/svg/svg_mobject.py @@ -5,6 +5,7 @@ from xml.etree import ElementTree as ET import numpy as np import svgelements as se +import io from manimlib.constants import RIGHT from manimlib.logger import log @@ -118,13 +119,13 @@ class SVGMobject(VMobject): file_path = self.get_file_path() element_tree = ET.parse(file_path) new_tree = self.modify_xml_tree(element_tree) - # Create a temporary svg file to dump modified svg to be parsed - root, ext = os.path.splitext(file_path) - modified_file_path = root + "_" + ext - new_tree.write(modified_file_path) - svg = se.SVG.parse(modified_file_path) - os.remove(modified_file_path) + # New svg based on tree contents + data_stream = io.BytesIO() + new_tree.write(data_stream) + data_stream.seek(0) + svg = se.SVG.parse(data_stream) + data_stream.close() mobjects = self.get_mobjects_from(svg) self.add(*mobjects)