python-lottie  0.6.11+devcecd248
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"], [
21  ExtraOption("animated", action="store_true", help="Export animated svg"),
22 ], {"pretty", "frame"})
23 def export_svg(animation, file, frame=0, pretty=True, animated=False):
24  _print_xml = _print_pretty_xml if pretty else _print_ugly_xml
25  _print_xml(to_svg(animation, frame, animated), file)
lottie.utils.file.open_file
def open_file(file_or_name, mode="w")
Definition: file.py:5
lottie.parsers.baseporter.ExtraOption
Definition: baseporter.py:32
lottie.parsers.svg.builder.to_svg
def to_svg(animation, time, animated=False)
Definition: builder.py:741
lottie.exporters.base.exporter
exporter
Definition: base.py:32
lottie.exporters.svg.export_svg
def export_svg(animation, file, frame=0, pretty=True, animated=False)
Definition: svg.py:23