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 areIMGTYP.JPEG
andIMGTYP.PNG
. Default isIMGTYP.JPEG
.
- img (
-
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)