Package: rlottie-python
rlottie-pythonA ctypes API for rlottie, with additional functions for getting Pillow Image and animated sequences, as well as telegram animated stickers (tgs).See example/example.py for example usage.The functions mostly followrlottie/inc/rlottie.hDocumentations:https://rlottie-python.readthedocs.io/en/latest/Table of contentsInstallingBuilding from sourceExamplesComparing to other libraryCreditsInstallingNote that rlottie is included in the wheel package, you need not install librlottie.To install, run the following:pip3 install wheel
pip3 install rlottie-pythonOptionally, installPillow:pip3 install PillowBuilding from sourceTo build wheel, run the following:git clone --recursive https://github.com/laggykiller/rlottie-python.git
cd rlottie-python
pip3 install -r requirements.txt
python3 -m build .To install the built wheel, runpip3 install dist/<name_of_the_wheel_file>.whlIf you want to install directly, run the following:gitclone--recursivehttps://github.com/laggykiller/rlottie-python.gitcdrlottie-python
pip3install-rrequirements.txt
pip3install.To run tests:pipinstallpytest
pytestExamplesGetting information about an lottie animationfromrlottie_pythonimportLottieAnimationanim=LottieAnimation.from_file("samples/sample.json")frames=anim.lottie_animation_get_totalframe()print(f"{frames= }")width,height=anim.lottie_animation_get_size()print(f"{width,height= }")duration=anim.lottie_animation_get_duration()print(f"{duration= }")totalframe=anim.lottie_animation_get_totalframe()print(f"{totalframe= }")framerate=anim.lottie_animation_get_framerate()print(f"{framerate= }")render_tree=anim.lottie_animation_render_tree(0)print(f"{render_tree.mMaskList.size= }")mapped_frame=anim.lottie_animation_get_frame_at_pos(0)print(f"{mapped_frame= }")Rendering and saving framefromrlottie_pythonimportLottieAnimationfromPILimportImageanim=LottieAnimation.from_file("samples/sample.json")# Method 1: Saving the frame to file directlyanim.save_frame("frame30.png",frame_num=30)# Method 2: Getting Pillow Imageim=anim.render_pillow_frame(frame_num=40)im.save("frame40.png")# Method 3: Getting bufferbuffer=anim.lottie_animation_render(frame_num=50)width,height=anim.lottie_animation_get_size()im=Image.frombuffer("RGBA",(width,height),buffer,"raw","BGRA")im.save("frame50.png")Loading from JSON file, string of JSON, tgs; and rendering animationfromrlottie_pythonimportLottieAnimation# Loading from fileanim=LottieAnimation.from_file("samples/sample.json")anim.save_animation("animation1.apng")anim=LottieAnimation.from_tgs("samples/sample.tgs")anim.save_animation("animation2.gif")withopen("samples/sample.json",encoding="utf-8")asf:data=f.read()anim=LottieAnimation.from_data(data=data)anim.save_animation("animation3.webp")You may also load animation using with statementfromrlottie_pythonimportLottieAnimationwithLottieAnimation.from_file("samples/sample.json")asanim:anim.save_animation("animation4.apng")Comparing to other libraryThelottie(https://pypi.org/project/lottie/) python package is also capable of working with lottie files and telegram animated stickers (tgs). It is also able to support many input/output formats and vector graphics, without any dependency on extenral libraries such as librlottie. However some images it creates is broken (Example1Example2). It seems librlottie is more stable in terms of rendering frames.Thepyrlottie(https://pypi.org/project/pyrlottie/) python package is also able to convert lottie and tgs files to webp/gif. However, it works by calling executablesgif2webpandlottie2gifwith subprocess, and it does not support macOS.Creditsrlottie library:https://github.com/Samsung/rlottiePackaging:https://github.com/tttapa/py-build-cmake