Skip to main content

PNG Process

pngencode

pngencode(img: np.ndarray, compression: int = 1) -> Union[bytes, None]

  • Description: Encodes a NumPy image array into a PNG format byte string.

  • Parameters:

    • img (np.ndarray): The image array to encode.
    • compression (int): The compression level, ranging from 0 to 9. 0 means no compression, and 9 represents maximum compression. Default is 1.
  • Return value:

    • bytes: The PNG format byte string after encoding.
  • Example:

    import numpy as np
    import capybara as cb

    img_array = np.random.rand(100, 100, 3) * 255
    encoded_bytes = cb.pngencode(img_array, compression=9)

pngdecode

pngdecode(byte_: bytes) -> Union[np.ndarray, None]

  • Description: Decodes a PNG format byte string into a NumPy image array.

  • Parameters:

    • byte_ (bytes): The PNG format byte string to decode.
  • Return value:

    • np.ndarray: The image array after decoding.
  • Example:

    decoded_img = cb.pngdecode(encoded_bytes)