mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 11:17:43 +00:00
Use io.BytesIO rather than writing to a temp file
This commit is contained in:
parent
8d05431b7b
commit
71c9144952
1 changed files with 7 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue