File size: 1,278 Bytes
6248155
b029a33
 
 
 
 
 
6248155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
import base64
import os

def get_base64_images():
    images = {}
    static_dir = 'static/images'
    
    try:
        # Create static/images directory if it doesn't exist
        os.makedirs(static_dir, exist_ok=True)
        
        print(f"Looking for images in: {static_dir}")
        
        # Load all image files in the directory
        if os.path.exists(static_dir):
            for image_file in os.listdir(static_dir):
                if image_file.lower().endswith(('.png', '.jpg', '.jpeg')):
                    try:
                        with open(os.path.join(static_dir, image_file), 'rb') as f:
                            # Get filename without extension as the key
                            name = os.path.splitext(image_file)[0].lower()
                            images[name] = base64.b64encode(f.read()).decode()
                            print(f"Loaded: {image_file}")
                    except Exception as e:
                        print(f"Error loading {image_file}: {e}")
        else:
            print(f"Warning: Directory not found: {static_dir}")
                    
    except Exception as e:
        print(f"Error in get_base64_images: {e}")
        print(f"Current working directory: {os.getcwd()}")
        
    return images