A framework to work with lottie files and telegram animated stickers (tgs)
Project description
Python Lottie
A Python framework to work with Lottie files and Telegram animated stickers.
Scripts
-
bin/lottie_convert.py
Script that can convert between several formats passing through lottie (see table under Supported Formats)
-
bin/lottie_cat.py
Prints the given lottie file into a human-readable format
-
bin/lottie_diff.py
Shows a side-by-side diff of the human-readable rendition of two lottie files
-
bin/raster_palette.py
Shows the palette of a raster image, to use with
bin/lottie_convert.py
-
bin/lottie_color.py
Converts a CSS color into a normalized array, as used in lottie
-
bin/jsoncat.py
Pretty prints a JSON file (useful to debug / diff lottie files)
-
bin/jsondiff.py
Pretty prints two JSON files side by side, highlighting differences (useful to debug / diff lottie files)
-
bin/lottie_cat.py
Pretty prints a lottie file with more readable annotations (useful to debug / diff lottie files)
-
bin/lottie_diff.py
Pretty prints two lottie files side by side, highlighting differences (useful to debug / diff lottie files)
-
bin/tgs_check.py
Checks a lottie or tgs file to see if it's compatible with telegram stickers
Installation
Synfig
There's a Synfig studio plugin to export telegram stickers. To install, just copy (or symlink) ./addons/synfig/tgs-exporter into the synfig plugin directory. You might have to copy ./lib/lottie in there as well.
You can download a zipfile from http://mattia.basaglia.gitlab.io/python-lottie/downloads.html
Inkscape
There are some import/export extensions for inkscape.
Just copy (or symlink) the files under ./addons/inkscape to the inkscape extension directory. On my system that's ~/.config/inkscape/extensions/ but you can double check from Inkscape: Edit > Preferences... > System > User extensions
Note that the extensions require Python 3.
If they are run with a python 2 interpreter, they will try to run themselves using python3
.
They also need the lottie framework to be in the python path, otherwise you can manually set the path on the import/export dialogues.
See also https://inkscape.org/~mattia.basaglia/%E2%98%85tgslottie-importexport
You can download a zipfile from http://mattia.basaglia.gitlab.io/python-lottie/downloads.html
Blender
There are some export addons for blender.
Copy (or symlink) the files under ./addons/blender to the Blender extension directory.
On my system that's ~/.config/blender/2.80/scripts/addons/ you can check available paths through the Blender Python console:
import addon_utils; print(addon_utils.paths())
You can also install the addon from Blender using the zipfile created by make
.
You can download a zipfile from http://mattia.basaglia.gitlab.io/python-lottie/downloads.html
Pip
You can install from pypi:
pip install lottie
from git:
pip install git+https://gitlab.com/mattia.basaglia/python-lottie.git@master
for the source directory:
pip install /path/to/the/sources # this is the path where setup.py is located
Requirements
Python 3.
Optional Requirements
coverage
To show unit test coverage, used optionally bytest.sh
pillow
,pypotrace>=0.2
,numpy
,scipy
To convert raster images into vectorspillow
To load image assetscairosvg
To export PNG / PDF / PScairosvg
,pillow
To export GIFcairosvg
,numpy
, Python OpenCV 2 To export videofonttools
To render text as shapes
Features
Here is a list of features of the lottie python framework:
- Loading compressed TGS and uncompressed lottie JSON
- Manipulation of lottie objects
- Simple animation presets (eg: shake, linear bounce)
- Bezier path animations (eg: follow path, making paths appear and disappear)
- Wave distortion animation (eg: for flags)
- Pseudo-3D rotations
- Animation easing functions
- Inverse Kinematic solver
- Pretty printing and comparison of lottie files
- Rendering text as shapes
Supported Formats
Format | Import | Import Animated | Export | Export Animated |
---|---|---|---|---|
lottie | ๐ | ๐ | ๐ | ๐ |
tgs | ๐ | ๐ | ๐ | ๐ |
SVG | ๐ | ๐ | ๐ | โ๏ธ |
SVGz | ๐ | ๐ | ๐ | โ๏ธ |
PNG | ๐ | ๐[^frames] | ๐ | โ๏ธ |
Synfig | ๐ | ๐ | ๐ | ๐ |
WebP | ๐ | ๐ | ๐ | ๐ |
dotLottie | ๐ | ๐ | ๐ | ๐ |
PostScript | โ๏ธ | โ๏ธ | ๐ | โ๏ธ |
โ๏ธ | โ๏ธ | ๐ | โ๏ธ | |
BMP | ๐ | ๐[^frames] | โ๏ธ | โ๏ธ |
GIF | ๐ | ๐ | ๐ | ๐ |
TIFF | ๐ | ๐ | ๐ | ๐ |
MP4 | โ๏ธ | โ๏ธ | ๐ | ๐ |
AVI | โ๏ธ | โ๏ธ | ๐ | ๐ |
WebM | โ๏ธ | โ๏ธ | ๐ | ๐ |
HTML | โ๏ธ | โ๏ธ | ๐ | ๐ |
Blender | ๐[^blend] | ๐[^blend] | โ๏ธ | โ๏ธ |
[^frames]: Importing multiple images as frames
[^blend]: Conversion available as a Blender addon
Telegram Animated Stickers
I had to reverse engineer the format because Telegram couldn't be bothered providing the specs.
A TGS file is a gzip compressed JSON, the JSON data is described here: https://mattia.basaglia.gitlab.io/python-lottie/group__Lottie.html#lottie_json
Making your own exporters converters
Lottie format
If you can get the source image into lottie format, that's 90% of the work done.
I've created Python classes based the format schema and after effects documentation, which output the correct json. Eg:
foo = lottie.Animation()
# ...
json.dump(foo.to_dict(), output_file)
I'm also creating a proper documentation for the format, see: https://mattia.basaglia.gitlab.io/tgs/group__Lottie.html#details
TGS changes
Nothing major, just ensure the root JSON object has tgs: 1
Gzipping
The tgs file is the JSON described above compressed into a gzip, and renamed to .tgs
License
AGPLv3+ https://www.gnu.org/licenses/agpl-3.0.en.html
Credits
Copyright 2019 (C) Mattia Basaglia
Links
Documentation
http://mattia.basaglia.gitlab.io/python-lottie/index.html
Code
https://gitlab.com/mattia.basaglia/python-lottie/
Chat
Download
http://mattia.basaglia.gitlab.io/python-lottie/downloads.html
Here you can download packages for pip, blender, and inkscape before they are released. These packages always have the latest features but they might be unstable.
Supported After Effects Features
Compare with http://airbnb.io/lottie/#/supported-features
Legend
- ๐ Supported
- โ Unknown / untested
- โ๏ธ Not supported
- python-lottie refers to this framework in general
- Telegram refers to features supported by telegram animated stickers
- SVG refers to the exported SVG images from this framework, features supported here will also reflect on other formats (such as video, png, and similar)
Telegram doesn't support everything in the Lottie format. https://core.telegram.org/animated_stickers lists some things that are unsupported but what is listed there isn't correct.
There are several things marked as unsupported in telegram animated stickers that are actually supported.
Shapes | python-lottie | Telegram | SVG |
---|---|---|---|
Shape | ๐ | ๐ | ๐ |
Ellipse | ๐ | ๐ | ๐ |
Rectangle | ๐ | ๐ | ๐ |
Rounded Rectangle | ๐ | ๐ | ๐ |
Polystar | ๐ | ๐[^unsuported] | ๐ |
Group | ๐ | ๐ | ๐ |
Trim Path (individually) | ๐ | ๐ | ๐ |
Trim Path (simultaneously) | ๐ | ๐ | ๐ |
Fills | python-lottie | Telegram | SVG |
Color | ๐ | ๐ | ๐ |
Opacity | ๐ | ๐ | ๐ |
Radial Gradient | ๐ | ๐ | ๐ |
Linear Gradient | ๐ | ๐ | ๐ |
Fill Rule | ๐ | ๐ | ๐ |
Strokes | python-lottie | Telegram | SVG |
Color | ๐ | ๐ | ๐ |
Opacity | ๐ | ๐ | ๐ |
Width | ๐ | ๐ | ๐ |
Line Cap | ๐ | ๐ | ๐ |
Line Join | ๐ | ๐ | ๐ |
Miter Limit | ๐ | ๐ | ๐ |
Dashes | ๐ | ๐ | ๐ |
Gradient | ๐ | ๐[^unsuported] | ๐ |
Transforms | python-lottie | Telegram | SVG |
Position | ๐ | ๐ | ๐ |
Position (separated X/Y) | ๐ | ๐ | ๐ |
Scale | ๐ | ๐ | ๐ |
Rotation | ๐ | ๐ | ๐ |
Anchor Point | ๐ | ๐ | ๐ |
Opacity | ๐ | ๐ | ๐ |
Parenting | ๐ | ๐ | ๐ |
Skew | ๐ | โ๏ธ[^bug] | ๐ |
Auto Orient | ๐ | ๐[^unsuported] | ๐ |
Interpolation | python-lottie | Telegram | SVG |
Linear Interpolation | ๐ | ๐ | ๐ |
Bezier Interpolation | ๐ | ๐ | ๐ |
Hold Interpolation | ๐ | ๐ | ๐ |
Spatial Bezier Interpolation | ๐ | ๐ | ๐ |
Rove Across Time | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
Masks | python-lottie | Telegram | SVG |
Mask Path | ๐ | ๐[^unsuported] | ๐ |
Mask Opacity | ๐ | ๐[^unsuported] | ๐ |
Add | ๐ | ๐[^unsuported] | โ๏ธ |
Subtract | ๐ | ๐[^unsuported] | โ๏ธ |
Intersect | ๐ | ๐[^unsuported] | ๐ |
Lighten | ๐ | ๐[^unsuported] | โ๏ธ |
Darken | ๐ | ๐[^unsuported] | โ๏ธ |
Difference | ๐ | ๐[^unsuported] | โ๏ธ |
Expansion | ๐ | ๐[^unsuported] | โ๏ธ |
Feather | ๐ | ๐[^unsuported] | โ๏ธ |
Mattes | python-lottie | Telegram | SVG |
Alpha Matte | ๐ | โ๏ธ[^dok] | โ๏ธ |
Alpha Inverted Matte | ๐ | โ๏ธ[^dok] | โ๏ธ |
Luma Matte | ๐ | โ๏ธ[^dok] | โ๏ธ |
Luma Inverted Matte | ๐ | โ๏ธ[^dok] | โ๏ธ |
Merge Paths | python-lottie | Telegram | SVG |
Merge | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
Add | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
Subtract | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
Intersect | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
Exclude Intersection | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
Layer Effects | python-lottie | Telegram | SVG |
Fill | ๐ | โ๏ธ | โ๏ธ |
Stroke | ๐ | โ๏ธ | โ๏ธ |
Tint | ๐ | โ๏ธ | โ๏ธ |
Tritone | ๐ | โ๏ธ | โ๏ธ |
Levels Individual Controls | ๐ | โ๏ธ | โ๏ธ |
Text [^text] | python-lottie | Telegram | SVG |
Glyphs | ๐ | โ๏ธ | โ๏ธ |
Fonts | ๐ | โ๏ธ | โ๏ธ |
Transform | ๐ | โ๏ธ | โ๏ธ |
Fill | ๐ | โ๏ธ | ๐ |
Stroke | ๐ | โ๏ธ | โ๏ธ |
Tracking | โ๏ธ | โ๏ธ | โ๏ธ |
Anchor point grouping | โ๏ธ | โ๏ธ | โ๏ธ |
Text Path | โ๏ธ | โ๏ธ | โ๏ธ |
Per-character 3D | โ๏ธ | โ๏ธ | โ๏ธ |
Range selector (Units) | โ๏ธ | โ๏ธ | โ๏ธ |
Range selector (Based on) | โ๏ธ | โ๏ธ | โ๏ธ |
Range selector (Amount) | โ๏ธ | โ๏ธ | โ๏ธ |
Range selector (Shape) | โ๏ธ | โ๏ธ | โ๏ธ |
Range selector (Ease High) | โ๏ธ | โ๏ธ | โ๏ธ |
Range selector (Ease Low) | โ๏ธ | โ๏ธ | โ๏ธ |
Range selector (Randomize order) | โ๏ธ | โ๏ธ | โ๏ธ |
expression selector | โ๏ธ | โ๏ธ | โ๏ธ |
Other | python-lottie | Telegram | SVG |
Expressions | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
Images | ๐ | โ๏ธ | ๐ |
Precomps | ๐ | ๐ | ๐ |
Time Stretch | ๐ | โ๏ธ | โ๏ธ |
Time remap | ๐ | โ๏ธ[^dok] | ๐ |
Markers | โ๏ธ | โ๏ธ[^untested] | โ๏ธ |
3D Layers | ๐ | โ๏ธ[^untested] | โ๏ธ |
Repeaters | ๐ | ๐[^unsuported] | ๐ |
Solids | ๐ | ๐[^unsuported] | ๐ |
[^text]: Note that python-lottie offers an alternative to lottie text layers, and can render text as shapes, so that is supported everywhere
[^untested]: Marked as unsuported but I haven't tested it
[^bug]: Not listed as unsupported, maybe a bug?
[^dok]: Works on telegram desktop
[^unsuported]: Marked as unsupported
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.