Skip to main content

imencode

imencode(img: np.ndarray, IMGTYP: Union[str, int, IMGTYP] = IMGTYP.JPEG) -> Union[bytes, None]

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

  • Parameters:

    • img (np.ndarray): The image array to encode.
    • IMGTYP (Union[str, int, IMGTYP]): The image type. Supported types are IMGTYP.JPEG and IMGTYP.PNG. Default is IMGTYP.JPEG.
  • Return value:

    • bytes: The encoded image byte string.
  • Example:

    import capybara as cb

    img = cb.imread('lena.png')
    encoded_bytes = cb.imencode(img, IMGTYP=cb.IMGTYP.PNG)