apngasm_python.apngasm¶
Classes¶
Python class for binding apngasm library |
Module Contents¶
- class apngasm_python.apngasm.APNGAsmBinder¶
Python class for binding apngasm library
- color_type_dict¶
- apngasm¶
- __enter__()¶
-
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.
-
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.
-
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’)
-
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]]
-
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
-
frame_palette_size(frame: int, new_value: int | None =
None) int | None¶ Get/Set the palette data size of frame.
-
frame_transparency_size(frame: int, new_value: int | None =
None) int | None¶ Get/Set the transparency data size of frame.
-
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.
-
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.
-
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.
-
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.
-
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.
- 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.
- disassemble_as_pillow(file_path: str) list[PIL.Image.Image]¶
Disassembles an APNG file to a list of frames, expressed as Pillow images.
- save_pngs(output_dir: str) bool¶
Saves individual PNG files of the frames in the frame vector.
- 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
- save_json(output_path: str, image_dir: str) bool¶
Saves a JSON animation spec file. You probably won’t need to use this function
- save_xml(output_path: str, image_dir: str) bool¶
Saves an XML animation spec file.
-
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_skip_first(skip_first: bool)¶
Set flag of skip first frame.
- get_frames() list[apngasm_python._apngasm_python.APNGFrame]¶
Returns the frame vector.
- is_skip_first() bool¶
Returns the flag of skip first frame.
- 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.