### Build rlottie-python from source Source: https://github.com/laggykiller/rlottie-python/blob/master/docs/installing.md Builds the rlottie-python library from its source code. This method involves cloning the repository, installing build dependencies, and then building a wheel package or installing directly. This provides more flexibility for development or custom builds. ```bash git clone --recursive https://github.com/laggykiller/rlottie-python.git cd rlottie-python pip3 install -r requirements.txt python3 -m build . ``` ```bash git clone --recursive https://github.com/laggykiller/rlottie-python.git cd rlottie-python pip3 install -r requirements.txt pip3 install . ``` -------------------------------- ### Install rlottie-python using pip Source: https://github.com/laggykiller/rlottie-python/blob/master/docs/installing.md Installs the rlottie-python library using pip. This is the recommended method as it includes the necessary wheel package. Ensure pip is up-to-date. ```bash pip3 install wheel pip3 install rlottie-python ``` -------------------------------- ### Install rlottie-python Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Installs the rlottie-python library using pip. The optional '[full]' argument installs Pillow as well, which is required for certain rendering and saving functions. ```bash pip3 install rlottie-python pip3 install rlottie-python[full] ``` -------------------------------- ### Get Lottie Animation Information (Python) Source: https://github.com/laggykiller/rlottie-python/blob/master/docs/examples.md This snippet shows how to retrieve various properties of a Lottie animation loaded from a file. It demonstrates fetching the total number of frames, dimensions (width, height), duration, frame rate, and information about the render tree and mapped frames. It requires the 'rlottie_python' library. ```python from rlottie_python import LottieAnimation anim = LottieAnimation.from_file('example/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 = }') ``` -------------------------------- ### Run Tests for rlottie-python Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Installs pytest and runs the test suite for the rlottie-python library to ensure its functionality. ```bash pip install pytest pytest ``` -------------------------------- ### Set Multiprocessing Start Method Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Provides guidance on setting the multiprocessing start method to 'spawn' when using rlottie_python in Linux, which can help prevent deadlocks when using `multiprocessing.Process`. ```python import multiprocessing if __name__ == "__main__": multiprocessing.set_start_method("spawn") ``` -------------------------------- ### Lint and Format rlottie-python Code Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Installs linting and formatting tools (ruff, mypy, isort) and runs them to check code quality and enforce style guidelines for the rlottie-python project. ```bash pip install ruff mypy isort mypy isort . ruff check ruff format ``` -------------------------------- ### Load Lottie Animation using 'with' statement (Python) Source: https://github.com/laggykiller/rlottie-python/blob/master/docs/examples.md This example shows how to load a Lottie animation from a file using Python's 'with' statement, which ensures that resources are properly managed and released after use. The animation is then saved to an APNG file. It requires the 'rlottie_python' library. ```python from rlottie_python import LottieAnimation with LottieAnimation.from_file('example/sample.json') as anim: anim.save_animation('animation4.apng') ``` -------------------------------- ### Render and Save Lottie Animation Frames (Python) Source: https://github.com/laggykiller/rlottie-python/blob/master/docs/examples.md This example illustrates different methods for rendering and saving individual frames of a Lottie animation. It covers saving a frame directly to a PNG file, obtaining a Pillow Image object for further manipulation, and rendering to a raw buffer that can then be converted into a Pillow Image. It requires 'rlottie_python' and 'Pillow'. ```python from rlottie_python import LottieAnimation from PIL import Image anim = LottieAnimation.from_file('example/sample.json') # Method 1: Saving the frame to file directly anim.save_frame('frame30.png', frame_num=30) # Method 2: Getting Pillow Image im = anim.render_pillow_frame(frame_num=40) im.save('frame40.png') # Method 3: Getting buffer buffer = 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') ``` -------------------------------- ### Get Lottie Animation Information Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Demonstrates how to load a Lottie animation from a file and retrieve various properties such as total frames, dimensions, duration, frame rate, and render tree information. It also shows how to get a mapped frame at a specific position. ```python from rlottie_python import LottieAnimation anim = 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 = }") ``` -------------------------------- ### Load Lottie Animation from Various Sources and Save Animation (Python) Source: https://github.com/laggykiller/rlottie-python/blob/master/docs/examples.md This snippet demonstrates loading Lottie animations from different sources including a JSON file, a TGS file, and a JSON string. It then shows how to save the entire animation into various output formats such as APNG, GIF, and WebP. Dependencies include 'rlottie_python'. ```python from rlottie_python import LottieAnimation # Loading from file anim = LottieAnimation.from_file('example/sample.json') anim.save_animation('animation1.apng') anim = LottieAnimation.from_tgs('example/sample.tgs') anim.save_animation('animation2.gif') with open('example/sample.json') as f: data = f.read() anim = LottieAnimation.from_data(data=data) anim.save_animation('animation3.webp') ``` -------------------------------- ### CMake Build Configuration for rlottie-python Source: https://github.com/laggykiller/rlottie-python/blob/master/CMakeLists.txt Configures the CMake build system for the rlottie-python project. It sets compiler flags based on the operating system (MSVC or Linux) and includes directives for installing the 'rlottie' target. ```cmake cmake_minimum_required(VERSION 3.17) project(rlottie-python) if (MSVC) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") elseif (LINUX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") endif() add_subdirectory(rlottie) # Install the module if (WIN32) install(TARGETS rlottie EXCLUDE_FROM_ALL RUNTIME DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME} COMPONENT python_module) else() install(TARGETS rlottie EXCLUDE_FROM_ALL LIBRARY DESTINATION ${PY_BUILD_CMAKE_MODULE_NAME} COMPONENT python_module) endif() ``` -------------------------------- ### Render and Save Lottie Animation Frames Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Illustrates different methods for rendering and saving frames from a Lottie animation. This includes saving directly to a file, obtaining a Pillow Image object for further manipulation, and getting a raw buffer to create an image manually. ```python from rlottie_python import LottieAnimation from PIL import Image anim = LottieAnimation.from_file("samples/sample.json") # Method 1: Saving the frame to file directly anim.save_frame("frame30.png", frame_num=30) # Method 2: Getting Pillow Image im = anim.render_pillow_frame(frame_num=40) im.save("frame40.png") # Method 3: Getting buffer buffer = 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") ``` -------------------------------- ### Build rlottie-python Wheel Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Commands to clone the rlottie-python repository and build a wheel package. This is useful for developers who want to build the library from source. ```bash git clone --recursive https://github.com/laggykiller/rlottie-python.git cd rlottie-python # To build wheel python3 -m build . # To install directly pip3 install . ``` -------------------------------- ### Use LottieAnimation with a Context Manager Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Demonstrates using the LottieAnimation object with a 'with' statement, which ensures proper resource management, particularly when saving animations to a file. ```python from rlottie_python import LottieAnimation with LottieAnimation.from_file("samples/sample.json") as anim: anim.save_animation("animation4.apng") ``` -------------------------------- ### Load Lottie Animation from Various Sources and Save Animation Source: https://github.com/laggykiller/rlottie-python/blob/master/README.md Shows how to load Lottie animations from different sources: a JSON file, a JSON string, and a Telegram animated sticker (tgs) file. It then demonstrates saving the animation to various formats like APNG, GIF, and WebP. ```python from rlottie_python import LottieAnimation # Loading from file anim = LottieAnimation.from_file("samples/sample.json") anim.save_animation("animation1.apng") anim = LottieAnimation.from_tgs("samples/sample.tgs") anim.save_animation("animation2.gif") with open("samples/sample.json", encoding="utf-8") as f: data = f.read() anim = LottieAnimation.from_data(data=data) anim.save_animation("animation3.webp") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.