apngasm_python.apngasm

Classes

APNGAsmBinder

Python class for binding apngasm library

Module Contents

class apngasm_python.apngasm.APNGAsmBinder

Python class for binding apngasm library

color_type_dict
apngasm
__enter__()
__exit__(exc_type, exc_val, exc_tb)
frame_pixels_as_pillow(frame: int, new_value: PIL.Image.Image | None = None) PIL.Image.Image | None

Get/Set the raw pixel data of frame, expressed as a Pillow object. This should be set AFTER you set the width, height and color_type.

Parameters:
frame : int

Target frame number.

new_value : Optional[PIL.Image.Image]

If set, then the raw pixel data of frame is set with this value.

Returns:

Pillow image object of the frame (get) or None (set)

Return type:

Optional[PIL.Image.Image]

frame_pixels_as_numpy(frame: int, new_value: numpy.typing.NDArray[Any] | None = None) numpy.typing.NDArray[Any] | None

Get/Set the raw pixel data of frame, expressed as a 3D numpy array. This should be set AFTER you set the width, height and color_type.

Parameters:
frame : int

Target frame number.

new_value : Optional[numpy.typing.NDArray[Any]]

If set, then the raw pixel data of frame is set with this value.

Returns:

3D numpy array representation of raw pixel data of frame (get) or None (set)

Return type:

Optional[numpy.typing.NDArray[Any]]

frame_width(frame: int, new_value: int | None = None) int | None

Get/Set the width of frame.

Parameters:
frame : int

Target frame number.

new_value : Optional[int]

If set, then the width of frame is set with this value.

Returns:

width (get) or None (set)

Return type:

Optional[int]

frame_height(frame: int, new_value: int | None = None) int | None

Get/Set the height of frame.

Parameters:
frame : int

Target frame number.

new_value : Optional[int]

If set, then the height of frame is set with this value.

Returns:

height (get) or None (set)

Return type:

Optional[int]

frame_color_type(frame: int, new_value: int | None = None) int | None

Get/Set the color_type of frame.

0: Grayscale (Pillow mode=’L’) 2: RGB (Pillow mode=’RGB’) 3: Palette (Pillow mode=’P’) 4: Grayscale + Alpha (Pillow mode=’LA’) 6: RGBA (Pillow mode=’RGBA’)

Parameters:
frame : int

Target frame number.

new_value : Optional[int]

If set, then the color type of frame is set with this value.

Returns:

color_type of frame (get) or None (set)

Return type:

Optional[int]

frame_palette(frame: int, new_value: numpy.typing.NDArray[Any] | None = None) numpy.typing.NDArray[Any] | None

Get/Set the palette data of frame. Only applies to ‘P’ mode Image (i.e. Not RGB, RGBA). Expressed as 2D numpy array in format of [[r0, g0, b0], [r1, g1, b1], …, [r255, g255, b255]]

Parameters:
frame : int

Target frame number.

new_value : Optional[numpy.typing.NDArray[Any]]

If set, then the palette data of frame is set with this value.

Returns:

2D numpy array representation of palette data of frame (get) or None (set)

Return type:

Optional[numpy.typing.NDArray[Any]]

frame_transparency(frame: int, new_value: numpy.typing.NDArray[Any] | None = None) numpy.typing.NDArray[Any] | None

Get/Set the color [r, g, b] to be treated as transparent in the frame, expressed as 1D numpy array. For more info, refer to ‘tRNS Transparency’ in http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html

Parameters:
frame : int

Target frame number.

new_value : Optional[numpy.typing.NDArray[Any]]

If set, then the transparency of frame is set with this value.

Returns:

The color [r, g, b] to be treated as transparent in the frame (get) or None (set)

Return type:

Optional[numpy.typing.NDArray[Any]]

frame_palette_size(frame: int, new_value: int | None = None) int | None

Get/Set the palette data size of frame.

Parameters:
frame : int

Target frame number.

new_value : Optional[int]

If set, then the palette data size of frame is set with this value.

Returns:

Palette data size of frame (get) or None (set)

Return type:

Optional[int]

frame_transparency_size(frame: int, new_value: int | None = None) int | None

Get/Set the transparency data size of frame.

Parameters:
frame : int

Target frame number.

new_value : Optional[int]

If set, then the transparency data size of frame is set with this value.

Returns:

Transparency data size of frame (get) or None (set)

Return type:

Optional[int]

frame_delay_num(frame: int, new_value: int | None = None) int | None

Get/Set the nominator of the duration of frame. Duration of time is delay_num / delay_den seconds.

Parameters:
frame : int

Target frame number.

new_value : Optional[int]

If set, then the nominator of the duration of frame is set with this value.

Returns:

Nominator of the duration of frame.

Return type:

Optional[int]

frame_delay_den(frame: int, new_value: int | None = None) int | None

Get/Set the denominator of the duration of frame. Duration of time is delay_num / delay_den seconds.

Parameters:
frame : int

Target frame number.

new_value : Optional[int]

If set, then the denominator of the duration of frame is set with this value.

Returns:

Denominator of the duration of frame.

Return type:

Optional[int]

add_frame_from_file(file_path: str, delay_num: int = 100, delay_den: int = 1000) int

Adds a frame from a PNG file or frames from a APNG file to the frame vector.

Parameters:
file_path : str

The relative or absolute path to an image file.

delay_num : int

The delay numerator for this frame (defaults to 100).

delay_den : int

The delay denominator for this frame (defaults to 1000).

Returns:

The new number of frames.

Return type:

int

add_frame_from_pillow(pillow_image: PIL.Image.Image, delay_num: int = 100, delay_den: int = 1000) int

Add a frame from Pillow image. The frame duration is equal to delay_num / delay_den seconds. Default frame duration is 100/1000 second, or 0.1 second.

Parameters:
pillow_image : PIL.Image.Image

Pillow image object.

delay_num : int

The delay numerator for this frame (defaults to 100).

delay_den : int

The delay denominator for this frame (defaults to 1000).

Returns:

The new number of frames.

Return type:

int

add_frame_from_numpy(numpy_data: numpy.typing.NDArray[Any], width: int | None = None, height: int | None = None, trns_color: numpy.typing.NDArray[Any] | None = None, mode: str | None = None, delay_num: int = 100, delay_den: int = 1000) int

Add frame from numpy array. The frame duration is equal to delay_num / delay_den seconds. Default frame duration is 100/1000 second, or 0.1 second.

Parameters:
numpy_data : numpy.typing.NDArray[Any]

The pixel data, expressed as 3D numpy array.

width : Optional[int]

The width of the pixel data. If not given, the 2nd dimension size of numpy_data is used.

height : Optional[int]

The height of the pixel data. If not given, the 1st dimension size of numpy_data is used.

mode : Optional[str]

The color mode of data. Possible values are RGB or RGBA. If not given, it is determined using the 3rd dimension size of numpy_data.

trns_color : Optional[numpy.typing.NDArray[Any]]

The color [r, g, b] to be treated as transparent, expressed as 1D numpy array. Only use if RGB mode.

delay_num : int

The delay numerator for this frame (defaults to 100).

delay_den : int

The delay denominator for this frame (defaults to 1000).

Returns:

The new number of frames.

Return type:

int

assemble(output_path: str) bool

Assembles and outputs an APNG file.

Parameters:
output_path : str

The output file path.

Returns:

true if assemble completed succesfully.

Return type:

bool

disassemble_as_numpy(file_path: str) list[numpy.typing.NDArray[Any]]

Disassembles an APNG file to a list of frames, expressed as 3D numpy array.

Parameters:
file_path : str

The file path to the PNG image to be disassembled.

Returns:

A list containing the frames of the disassembled PNG.

Return type:

list[numpy.typing.NDArray[Any]]

disassemble_as_pillow(file_path: str) list[PIL.Image.Image]

Disassembles an APNG file to a list of frames, expressed as Pillow images.

Parameters:
file_path : str

The file path to the PNG image to be disassembled.

Returns:

A list containing the frames of the disassembled PNG.

Return type:

list[PIL.Image.Image]

save_pngs(output_dir: str) bool

Saves individual PNG files of the frames in the frame vector.

Parameters:
output_dir : str

The directory where the PNG fils will be saved.

Returns:

true if all files were saved successfully.

Return type:

bool

load_animation_spec(file_path: str) list[apngasm_python._apngasm_python.APNGFrame]

Loads an animation spec from JSON or XML. Loaded frames are added to the end of the frame vector. For more details on animation specs see: https://github.com/Genshin/PhantomStandards You probably won’t need to use this function

Parameters:
file_path : str

The path of JSON or XML file.

Returns:

A vector containing the loaded frames.

Return type:

list[apngasm_python._apngasm_python.APNGFrame]

save_json(output_path: str, image_dir: str) bool

Saves a JSON animation spec file. You probably won’t need to use this function

Parameters:
output_path : str

Path to save the file to.

image_dir : str

Directory where frame files are to be saved if not the same path as the animation spec.

Returns:

true if save was successful.

Return type:

bool

save_xml(output_path: str, image_dir: str) bool

Saves an XML animation spec file.

Parameters:
filePath : str

Path to save the file to.

image_dir : str

Directory where frame files are to be saved if not the same path as the animation spec.

Returns:

true if save was successful.

Return type:

bool

abstractmethod set_apngasm_listener(listener: apngasm_python._apngasm_python.IAPNGAsmListener | None = None)

Sets a listener. You probably won’t need to use this function.

Parameters:
listener : Optional[apngasm_python._apngasm_python.IAPNGAsmListener]

A pointer to the listener object. If the argument is None, a default APNGAsmListener will be created and assigned.

set_loops(loops: int = 0)

Set loop count of animation.

Parameters:
loops : int

Loop count of animation. If the argument is 0 a loop count is infinity.

set_skip_first(skip_first: bool)

Set flag of skip first frame.

Parameters:
skip_first : bool

Flag of skip first frame.

get_frames() list[apngasm_python._apngasm_python.APNGFrame]

Returns the frame vector.

Returns:

frame vector.

Return type:

list[apngasm_python._apngasm_python.APNGFrame]

get_loops() int

Returns the loop count.

Returns:

loop count.

Return type:

int

is_skip_first() bool

Returns the flag of skip first frame.

Returns:

flag of skip first frame.

Return type:

bool

frame_count() int

Returns the number of frames.

Returns:

number of frames.

Return type:

int

reset() int

Destroy all frames in memory/dispose of the frame vector. Leaves the apngasm object in a clean state. Returns number of frames disposed of.

Returns:

number of frames disposed of.

Return type:

int

version() str

Returns the version of APNGAsm.

Returns:

version of APNGAsm.

Return type:

str