Skip to main content

imencode

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

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

  • Parameters

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

    • bytes: The encoded image byte string.
  • Example

    import docsaidkit as D

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