python-lottie  0.6.11+deved4e6c7
A framework to work with lottie files and telegram animated stickers (tgs)
svg.py
Go to the documentation of this file.
1 from xml.dom import minidom
2 from xml.etree import ElementTree
3 
4 from .base import exporter
5 from ..parsers.baseporter import ExtraOption
6 from ..parsers.svg.builder import to_svg
7 from ..utils.file import open_file
8 
9 
10 def _print_ugly_xml(dom, file):
11  return dom.write(file, "utf-8", True)
12 
13 
14 def _print_pretty_xml(dom, file):
15  with open_file(file) as fp:
16  xmlstr = minidom.parseString(ElementTree.tostring(dom.getroot())).toprettyxml(indent=" ")
17  fp.write(xmlstr)
18 
19 
20 @exporter("SVG", ["svg"], [ ExtraOption("animated", action="store_true", help="Export animated svg"),
21 ], {"pretty", "frame"})
22 def export_svg(animation, file, frame=0, pretty=True, animated=False):
23  _print_xml = _print_pretty_xml if pretty else _print_ugly_xml
24  _print_xml(to_svg(animation, frame, animated), file)
25 
def export_svg(animation, file, frame=0, pretty=True, animated=False)
Definition: svg.py:23
def to_svg(animation, time, animated=False)
Definition: builder.py:744
def open_file(file_or_name, mode="w")
Definition: file.py:5