in src/sagemaker_huggingface_inference_toolkit/decoder_encoder.py [0:0]
def encode_image(image, accept_type=content_types.PNG):
"""Convert a PIL.Image object to a byte stream.
Args:
image (PIL.Image): image to be converted.
accept_type (str): content type of the image.
Returns:
(bytes): byte stream of the image.
"""
accept_type = "PNG" if content_types.X_IMAGE == accept_type else accept_type.split("/")[-1].upper()
with BytesIO() as out:
image.save(out, format=accept_type)
return out.getvalue()