Spaces:
Running
Running
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}") | |