rlottie_python package

Submodules

rlottie_python.rlottie_wrapper module

class rlottie_python.rlottie_wrapper.LottieAnimation(path: str = '', data: str = '', key_size: int | None = None, resource_path: str | None = None, rlottie_lib_path: str | None = None)

Bases: object

classmethod from_data(data: str, key_size: int | None = None, resource_path: str | None = None, rlottie_lib_path: str | None = None) LottieAnimation

Constructs LottieAnimation object from JSON string data.

Parameters:
data : str

the JSON string data.

key_size : Optional[int]

the string that will be used to cache the JSON string data.

resource_path : Optional[str]

the path that will be used to load external resource needed by the JSON data.

rlottie_lib_path : Optional[str]

Optionally specific where the rlottie library is located

Returns:

LottieAnimation object

Return type:

LottieAnimation

classmethod from_file(path: str, rlottie_lib_path: str | None = None) LottieAnimation

Constructs LottieAnimation object from lottie file path.

Parameters:
path : str

lottie resource file path

rlottie_lib_path : Optional[str]

Optionally specific where the rlottie library is located

Returns:

LottieAnimation object

Return type:

LottieAnimation

classmethod from_tgs(path: str, rlottie_lib_path: str | None = None) LottieAnimation

Constructs LottieAnimation object from tgs file path.

Parameters:
path : str

tgs resource file path

rlottie_lib_path : Optional[str]

Optionally specific where the rlottie library is located

Returns:

LottieAnimation object

Return type:

LottieAnimation

lottie_animation_destroy() None

Free given Animation object resource.

Call this before loading new lottie animation.

lottie_animation_from_data(data: str, key_size: int | None = None, resource_path: str | None = None) None

Constructs an animation object from JSON string data.

Note

You should use from_data(data=data) instead

Parameters:
data : str

the JSON string data.

key_size : Optional[int]

the size of string that will be used to cache the JSON string data.

resource_path : Optional[str]

the path that will be used to load external resource needed by the JSON data.

lottie_animation_from_file(path: str) None

Constructs an animation object from JSON file path.

Note

You should use from_file(path=path) instead

Parameters:
path : str

lottie resource file path

lottie_animation_get_duration() int

Returns total animation duration of Lottie resource in second.

Returns:

duration

Return type:

int

lottie_animation_get_frame_at_pos(pos: float) int

Maps position to frame number and returns it.

Parameters:
pos : float

position in the range [ 0.0 .. 1.0 ].

Returns:

Mapped frame number in the range [ start_frame .. end_frame ]. 0 if the Lottie resource has no animation.

Return type:

int

lottie_animation_get_framerate() int

Returns default framerate of the Lottie resource.

Returns:

framerate

Return type:

int

lottie_animation_get_markerlist() LOTMarkerList | None

Returns list of markers in the Lottie resource

LOTMarkerList has a LOTMarker list and size of list

LOTMarker has the marker’s name, start frame, and end frame.

Example for getting content of markerlist: markerlist.ptr.name

Returns:

The list of marker. If there is no marker, return None

Return type:

Optional[LOTMarkerList]

lottie_animation_get_size() tuple[int, int]

Returns default viewport size of the Lottie resource.

Returns:

width, height

Return type:

Tuple[int, int]

lottie_animation_get_totalframe() int

Returns total number of frames present in the Lottie resource.

Returns:

totalframe

Return type:

int

lottie_animation_property_override(_type: LottieAnimationProperty, keypath: str, *args: c_double) None

Request to change the properties of this animation object.

Keypath should conatin object names separated by (.) and can handle globe(**) or wildchar(*)

Possible values of _types and args

_type LottieAnimationProperty

No. of args

args value

Description

LOTTIE_ANIMATION_PROPERTY_FILLCOLOR

3 args

[0 … 1]

Color property of Fill object:

LOTTIE_ANIMATION_PROPERTY_FILLOPACITY

1 args

[0 … 100]

Opacity property of Fill object

LOTTIE_ANIMATION_PROPERTY_STROKECOLOR

3 args

[0 … 1]

Color property of Stroke object

LOTTIE_ANIMATION_PROPERTY_STROKEOPACITY

1 args

[0 … 100]

Opacity property of Stroke object

LOTTIE_ANIMATION_PROPERTY_STROKEWIDTH

1 args

[0 … +inf]

Stroke width property of Stroke object

LOTTIE_ANIMATION_PROPERTY_TR_ANCHOR

0 args

Any

Transform Anchor property of Layer and Group object

LOTTIE_ANIMATION_PROPERTY_TR_POSITION

2 args

Any

Transform Position property of Layer and Group object

LOTTIE_ANIMATION_PROPERTY_TR_SCALE

2 args

Any

Transform Scale property of Layer and Group object

LOTTIE_ANIMATION_PROPERTY_TR_ROTATION

1 args

[0 … 360]

Transform Scale property of Layer and Group object

LOTTIE_ANIMATION_PROPERTY_TR_OPACITY

0 args

Any

Transform Opacity property of Layer and Group object

Example: To change fillcolor property of fill1 object in the layer1->group1->fill1 hirarchy to RED color:

lottie_animation_property_override(
    LottieAnimationProperty.LOTTIE_ANIMATION_PROPERTY_FILLCOLOR,
    "layer1.group1.fill1",
    ctypes.c_double(1.0),
    ctypes.c_double(0.0),
    ctypes.c_double(0.0)
)

If all the color property inside group1 needs to be changed to GREEN color:

lottie_animation_property_override(
    LottieAnimationProperty.LOTTIE_ANIMATION_PROPERTY_FILLCOLOR,
    "**.group1.**",
    ctypes.c_double(0.0),
    ctypes.c_double(1.0),
    ctypes.c_double(0.0)
)
Parameters:
_type : LottieAnimationProperty

Property type.

keypath : str

Specific content of target.

*args : ctypes.c_double

Property values.

lottie_animation_render(frame_num: int = 0, buffer_size: int | None = None, width: int | None = None, height: int | None = None, bytes_per_line: int | None = None) bytes

Request to render the content of the frame frame_num to buffer.

Parameters:
frame_num : int

the frame number needs to be rendered. Defaults to 0.

buffer_size : Optional[int]

size of surface buffer use for rendering

width : Optional[int]

width of the surface

height : Optional[int]

height of the surface

bytes_per_line : Optional[int]

stride of the surface in bytes.

Returns:

rendered surface buffer

Return type:

bytes

lottie_animation_render_async(frame_num: int = 0, buffer_size: int | None = None, width: int | None = None, height: int | None = None, bytes_per_line: int | None = None) None

Request to render the content of the frame frame_num to buffer asynchronously.

User must call lottie_animation_render_flush() to make sure render is finished.

Parameters:
frame_num : int

the frame number needs to be rendered. Defaults to 0.

buffer_size : Optional[int]

size of surface buffer use for rendering

width : Optional[int]

width of the surface

height : Optional[int]

height of the surface

bytes_per_line : Optional[int]

stride of the surface in bytes.

lottie_animation_render_flush() bytes

Request to finish the current async renderer job for this animation object.

If render is finished then this call returns immidiately.

If not, it waits till render job finish and then return.

User must call lottie_animation_render_async() and lottie_animation_render_flush() in pair to get the benefit of async rendering.

Returns:

the pixel buffer it finised rendering

Return type:

bytes

lottie_animation_render_tree(frame_num: int = 0, width: int | None = None, height: int | None = None) LOTLayerNode

Get the render tree which contains the snapshot of the animation object at frame = @c frame_num, the content of the animation in that frame number.

Example for getting content of render_tree: render_tree.mMaskList.size

Parameters:
frame_num : int

Content corresponds to the frame_num needs to be drawn. Defaults to 0.

width : Optional[int]

Requested snapshot viewport width.

height : Optional[int]

Requested snapshot viewport height.

Returns:

animation snapshot tree.

Return type:

rlottie_python.rlottiecommon.LOTLayerNode

lottie_configure_model_cache_size(cache_size: int) None

Configures rlottie model cache policy.

Provides Library level control to configure model cache policy.

Setting it to 0 will disable the cache as well as flush all the previously cached content.

To disable Caching, configure with 0 size.

To flush the current Cache content, configure it with 0 and then reconfigure with the new size.

Parameters:
cache_size : int

Maximum Model Cache size.

lottie_init() None

Runs lottie initialization code when rlottie library is loaded dynamically.

This api should be called before any other api when rlottie library is loaded using dlopen() or equivalent.

lottie_shutdown() None

Runs lottie teardown code when rlottie library is loaded dynamically.

This api should be called before unloading the rlottie library for proper cleanup of the resource without doing so will result in undefined behaviour.

render_pillow_frame(frame_num: int = 0, buffer_size: int | None = None, width: int | None = None, height: int | None = None, bytes_per_line: int | None = None) Image.Image

Create Pillow Image at frame_num

Parameters:
frame_num : int

the frame number needs to be rendered. Defaults to 0.

buffer_size : Optional[int]

size of surface buffer use for rendering

width : Optional[int]

width of the surface

height : Optional[int]

height of the surface

bytes_per_line : Optional[int]

stride of the surface in bytes.

Returns:

rendered Pillow Image

Return type:

PIL.Image.Image

save_animation(save_path: str, fps: int | None = None, frame_num_start: int | None = None, frame_num_end: int | None = None, buffer_size: int | None = None, width: int | None = None, height: int | None = None, bytes_per_line: int | None = None, *args: Any, **kwargs: Any) None

Save Image from frame_num_start to frame_num_end and save it to save_path.

It is possible to save animation as apng, gif or webp.

For .gif, maximum framerate is capped at 50.

Users may override this by specifying fps, at risk of breaking their gif.

Parameters:
save_path : str

Path to save the Pillow Image

fps : Optional[int]

Set fps of output image. Will skip frames if lower than original.

frame_num_start : Optional[int]

the starting frame number needs to be rendered.

frame_num_end : Optional[int]

the ending frame number needs to be rendered.

buffer_size : Optional[int]

size of surface buffer use for rendering

width : Optional[int]

width of the surface

height : Optional[int]

height of the surface

bytes_per_line : Optional[int]

stride of the surface in bytes.

*args : Any

additional arguments passing to im.save()

**kwargs : Any

additional arguments passing to im.save()

save_frame(save_path: str, frame_num: int = 0, buffer_size: int | None = None, width: int | None = None, height: int | None = None, bytes_per_line: int | None = None, *args: Any, **kwargs: Any) None

Save Image at frame_num to save_path

Parameters:
save_path : str

path to save the Pillow Image

frame_num : int

the frame number needs to be rendered. Defaults to 0.

buffer_size : Optional[int]

size of surface buffer use for rendering

width : Optional[int]

width of the surface

height : Optional[int]

height of the surface

bytes_per_line : Optional[int]

stride of the surface in bytes.

*args : Any

additional arguments passing to im.save()

**kwargs : Any

additional arguments passing to im.save()

class rlottie_python.rlottie_wrapper.LottieAnimationProperty(value)

Bases: IntEnum

LOTTIE_ANIMATION_PROPERTY_FILLCOLOR = 0
LOTTIE_ANIMATION_PROPERTY_FILLOPACITY = 1
LOTTIE_ANIMATION_PROPERTY_STROKECOLOR = 2
LOTTIE_ANIMATION_PROPERTY_STROKEOPACITY = 3
LOTTIE_ANIMATION_PROPERTY_STROKEWIDTH = 4
LOTTIE_ANIMATION_PROPERTY_TR_ANCHOR = 5
LOTTIE_ANIMATION_PROPERTY_TR_OPACITY = 9
LOTTIE_ANIMATION_PROPERTY_TR_POSITION = 6
LOTTIE_ANIMATION_PROPERTY_TR_ROTATION = 8
LOTTIE_ANIMATION_PROPERTY_TR_SCALE = 7
classmethod from_param(obj: int) int

Module contents

rlottie-python