import base64 # Library for encoding and decoding data in base64 format def encode_image(image_path: str) -> str: """ Encode an image file to a base64 string. Args: image_path (str): The file path of the image to be encoded. Returns: str: The base64-encoded string representation of the image. """ # Open the image file in binary read mode with open(image_path, "rb") as image_file: # Read the image content, encode it to base64, and decode it to a UTF-8 string return base64.b64encode(image_file.read()).decode('utf-8')