Spaces:
Sleeping
Sleeping
File size: 720 Bytes
00b1038 5842223 00b1038 5842223 00b1038 5842223 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import base64
def encode_image(image_path: str) -> str:
"""
Encodes an image file into a Base64 string.
Args:
image_path (str): The path to the image file.
Returns:
str: The Base64 encoded string representation of the image.
Raises:
FileNotFoundError: If the specified image file does not exist.
IOError: If there is an error reading the image file.
"""
try:
with open(image_path, "rb") as img_file:
return base64.b64encode(img_file.read()).decode()
except FileNotFoundError:
raise FileNotFoundError(f"Image file not found at: {image_path}")
except OSError as e:
raise OSError(f"Error reading image file: {e}")
|