Telegram Animated Stickers Tools
A Python framework to work with Telegram animated stickers.
Scripts
-
bin/tgsconvert.pyScript that can convert between several formats, including lottie / TGS
-
bin/tgscat.pyPrints the given tgs / lottie file into a human-readable format
-
bin/tgsdiff.pyShows a side-by-side diff of the human-readable rendition of two tgs / lottie files
-
bin/raster_palette.pyShows the palette of a raster image, to use with
bin/raster2tgs.py -
bin/tgscolor.pyConverts a CSS color into a normalized array, as used in lottie
-
bin/jsoncat.pyPretty prints a JSON file (useful to debug / diff lottie files)
-
bin/jsondiff.pyPretty prints two JSON files side by side, highlighting differences (useful to debug / diff lottie files)
-
bin/tgscat.pyPretty prints a tgs / lottie file with more readable annotations (useful to debug / diff lottie files)
-
bin/tgsdiff.pyPretty prints two tgs / lottie files side by side, highlighting differences (useful to debug / diff lottie files)
-
bin/tgscheck.pyChecks 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/tgs in there as well.
You can download a zipfile from http://mattia.basaglia.gitlab.io/tgs/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 tgs 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/tgs/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/tgs/downloads.html
Pip
You can install from pypi:
pip install tgs
from git:
pip install git+https://gitlab.com/mattia.basaglia/tgs.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
coverageTo show unit test coverage, used optionally bytest.shpillow,pypotrace>=0.2,numpy,scipyTo convert raster images into vectorspillowTo load image assetscairosvgTo export PNG / PDF / PScairosvg,pillowTo export GIFcairosvg,numpy, Python OpenCV 2 To export videofonttoolsTo render text as shapes
Features
Here is a list of features of the tgs 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 | 👍 | 👍1 | 👍 | ⛔️ |
| Synfig | 👍 | 👍 | 👍 | 👍 |
| WebP | 👍 | 👍 | 👍 | 👍 |
| dotLottie | 👍 | 👍 | 👍 | 👍 |
| PostScript | ⛔️ | ⛔️ | 👍 | ⛔️ |
| ⛔️ | ⛔️ | 👍 | ⛔️ | |
| BMP | 👍 | 👍1 | ⛔️ | ⛔️ |
| GIF | 👍 | 👍 | 👍 | 👍 |
| TIFF | 👍 | 👍 | 👍 | 👍 |
| MP4 | ⛔️ | ⛔️ | 👍 | 👍 |
| AVI | ⛔️ | ⛔️ | 👍 | 👍 |
| WebM | ⛔️ | ⛔️ | 👍 | 👍 |
| HTML | ⛔️ | ⛔️ | 👍 | 👍 |
| Blender | 👍2 | 👍2 | ⛔️ | ⛔️ |
Reverse Engineering
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/tgs/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 = tgs.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/tgs/index.html
Code
https://gitlab.com/mattia.basaglia/tgs/
Chat
Download
https://gitlab.com/mattia.basaglia/tgs/-/jobs/artifacts/master/download?job=build
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
- tgs 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 | tgs | Telegram | SVG |
|---|---|---|---|
| Shape | 👍 | 👍 | 👍 |
| Ellipse | 👍 | 👍 | 👍 |
| Rectangle | 👍 | 👍 | 👍 |
| Rounded Rectangle | 👍 | 👍 | 👍 |
| Polystar | 👍 | 👍3 | 👍 |
| Group | 👍 | 👍 | 👍 |
| Trim Path (individually) | 👍 | 👍 | 👍 |
| Trim Path (simultaneously) | 👍 | 👍 | 👍 |
| Fills | tgs | Telegram | SVG |
| Color | 👍 | 👍 | 👍 |
| Opacity | 👍 | 👍 | 👍 |
| Radial Gradient | 👍 | 👍 | 👍 |
| Linear Gradient | 👍 | 👍 | 👍 |
| Fill Rule | 👍 | 👍 | 👍 |
| Strokes | tgs | Telegram | SVG |
| Color | 👍 | 👍 | 👍 |
| Opacity | 👍 | 👍 | 👍 |
| Width | 👍 | 👍 | 👍 |
| Line Cap | 👍 | 👍 | 👍 |
| Line Join | 👍 | 👍 | 👍 |
| Miter Limit | 👍 | 👍 | 👍 |
| Dashes | 👍 | 👍 | 👍 |
| Gradient | 👍 | 👍3 | 👍 |
| Transforms | tgs | Telegram | SVG |
| Position | 👍 | 👍 | 👍 |
| Position (separated X/Y) | 👍 | 👍 | 👍 |
| Scale | 👍 | 👍 | 👍 |
| Rotation | 👍 | 👍 | 👍 |
| Anchor Point | 👍 | 👍 | 👍 |
| Opacity | 👍 | 👍 | 👍 |
| Parenting | 👍 | 👍 | 👍 |
| Skew | 👍 | ⛔️4 | 👍 |
| Auto Orient | 👍 | 👍3 | 👍 |
| Interpolation | tgs | Telegram | SVG |
| Linear Interpolation | 👍 | 👍 | 👍 |
| Bezier Interpolation | 👍 | 👍 | 👍 |
| Hold Interpolation | 👍 | 👍 | 👍 |
| Spatial Bezier Interpolation | 👍 | 👍 | 👍 |
| Rove Across Time | ⛔️ | ⛔️5 | ⛔️ |
| Masks | tgs | Telegram | SVG |
| Mask Path | 👍 | 👍3 | 👍 |
| Mask Opacity | 👍 | 👍3 | 👍 |
| Add | 👍 | 👍3 | ⛔️ |
| Subtract | 👍 | 👍3 | ⛔️ |
| Intersect | 👍 | 👍3 | 👍 |
| Lighten | 👍 | 👍3 | ⛔️ |
| Darken | 👍 | 👍3 | ⛔️ |
| Difference | 👍 | 👍3 | ⛔️ |
| Expansion | 👍 | 👍3 | ⛔️ |
| Feather | 👍 | 👍3 | ⛔️ |
| Mattes | tgs | Telegram | SVG |
| Alpha Matte | 👍 | ⛔️6 | ⛔️ |
| Alpha Inverted Matte | 👍 | ⛔️6 | ⛔️ |
| Luma Matte | 👍 | ⛔️6 | ⛔️ |
| Luma Inverted Matte | 👍 | ⛔️6 | ⛔️ |
| Merge Paths | tgs | Telegram | SVG |
| Merge | ⛔️ | ⛔️5 | ⛔️ |
| Add | ⛔️ | ⛔️5 | ⛔️ |
| Subtract | ⛔️ | ⛔️5 | ⛔️ |
| Intersect | ⛔️ | ⛔️5 | ⛔️ |
| Exclude Intersection | ⛔️ | ⛔️5 | ⛔️ |
| Layer Effects | tgs | Telegram | SVG |
| Fill | 👍 | ⛔️ | ⛔️ |
| Stroke | 👍 | ⛔️ | ⛔️ |
| Tint | 👍 | ⛔️ | ⛔️ |
| Tritone | 👍 | ⛔️ | ⛔️ |
| Levels Individual Controls | 👍 | ⛔️ | ⛔️ |
| Text 7 | tgs | 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 | tgs | Telegram | SVG |
| Expressions | ⛔️ | ⛔️5 | ⛔️ |
| Images | 👍 | ⛔️ | 👍 |
| Precomps | 👍 | 👍 | 👍 |
| Time Stretch | 👍 | ⛔️ | ⛔️ |
| Time remap | 👍 | ⛔️6 | 👍 |
| Markers | ⛔️ | ⛔️5 | ⛔️ |
| 3D Layers | 👍 | ⛔️5 | ⛔️ |
| Repeaters | 👍 | 👍3 | 👍 |
| Solids | 👍 | 👍3 | 👍 |
-
Marked as unsupported ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14 ↩15
-
Not listed as unsupported, maybe a bug? ↩
-
Marked as unsuported but I haven't tested it ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9
-
Note that tgs offers an alternative to lottie text layers, and can render text as shapes, so that is supported everywhere ↩
Metadata
Release files for tgs 0.5.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tgs-0.5.4.tar.gz | 102.5 kB | Details |
Release files / tgs-0.5.4.tar.gz
| Download URL | tgs-0.5.4.tar.gz |
|---|---|
| Size | 102.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3b4ffda8c5599d9a87f09ce3b1722129ef076157de9b6d30ec07650e24b8873
|
|
BLAKE2b-256 checksum How to use checksums |
3b313a93fe3ad374e720a019fe3d75913b4333dec01b753699ba655e8aea7e04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9
|