Skip to content

Lottie JSON to PNG/WebP/GIF conversion error

Hi, I was converting Lottie JSON files to various file formats for debugging when I encountered the below error in the convert script.

I resolved by updating the argument passed into color_to_css from doc.color to doc.fill_color https://gitlab.com/mattbas/python-lottie/-/blob/master/lib/lottie/parsers/svg/builder.py?ref_type=heads#L250

I assume this is because the TextDocument class does not have a color attribute by default. The docs have the fill_color as the actual color vector: https://mattbas.gitlab.io/python-lottie/classlottie_1_1objects_1_1text_1_1TextDocument.html#ad1c445de0b6d7650dfd0e21df0e34dbd

Thank you!

lottie_convert.py Error output:

  File "/Users/dev/envs/lottie/bin/lottie_convert.py", line 179, in <module>
    exporter.process(an, outfile, **o_options)
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/parsers/baseporter.py", line 18, in process
    return self.callback(*a, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/exporters/cairo.py", line 38, in export_png
    _export_cairo(cairosvg.svg2png, animation, fp, frame, dpi)
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/exporters/cairo.py", line 32, in _export_cairo
    export_svg(animation, intermediate, frame, pretty=False)
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/exporters/svg.py", line 25, in export_svg
    _print_xml(to_svg(animation, frame, animated), file)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/parsers/svg/builder.py", line 754, in to_svg
    builder.process(animation)
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/utils/restructure.py", line 106, in process
    self.process_layer(layer_builder, out_parent)
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/utils/restructure.py", line 121, in process_layer
    out_layer = self._on_layer(layer_builder, out_parent)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/parsers/svg/builder.py", line 211, in _on_layer
    self._on_text_layer(g, lot)
  File "/Users/dev/envs/lottie/lib/python3.12/site-packages/lottie/parsers/svg/builder.py", line 250, in _on_text_layer
    text.attrib["fill"] = color_to_css(doc.color)
                                       ^^^^^^^^^
AttributeError: 'TextDocument' object has no attribute 'color'

lottie_diagnostic.py Output:

* Python Lottie version: 0.7.2
* Available Importers:
  * Lottie JSON / Telegram Sticker
  * SVG
  * Synfig
  * OpenToonz
  * AfterEffect Project
  * AfterEffect Project XML
  * dotLottie Archive
  * Krita
  * Raster image
  * Python script
* Available Exporters:
  * Lottie JSON
  * Telegram Animated Sticker
  * Lottie HTML
  * SVG
  * Synfig
  * PNG
  * PDF
  * PostScript
  * GIF
  * WebP
  * TIFF
  * dotLottie Archive
  * Video