get_image_data
Loads an image and returns its data either as raw bytes or in base64-encoded format.
This function first loads an image from the specified file, URL, or base64 string using
the get_pil_image
function. It then saves this image in memory in PNG format and
retrieves its binary content. Depending on the use_b64
flag, this binary content is
either returned directly or as a base64-encoded string.
Parameters:
image_file (str, or Image): The path to the image file, a URL to an image, or a base64-encoded
string of the image.
use_b64 (bool): If True, the function returns a base64-encoded string of the image data.
If False, it returns the raw byte data of the image. Defaults to True.
Returns:
bytes: The image data in raw bytes if use_b64
is False, or a base64-encoded string
if use_b64
is True.
Parameters:
Name | Description |
---|
image_file | Type: str | ForwardRef(‘Image.Image’) |
use_b64=True | |
Returns:
Type | Description |
---|
bytes | bytes: The image data in raw bytes if use_b64 is False, or a base64-encoded string if use_b64 is True. |