File size: 585 Bytes
241c492
273089c
241c492
 
 
 
 
 
 
 
 
 
 
273089c
241c492
273089c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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')