""" Create simple test placeholder images for Canvas API testing """ from PIL import Image, ImageDraw, ImageFont import os def create_placeholder_image(path, text, color, size=(800, 600)): """Create a simple colored placeholder image with text""" # Create image with solid color img = Image.new('RGB', size, color) draw = ImageDraw.Draw(img) # Add text try: # Try to use a default font font = ImageFont.truetype("arial.ttf", 48) except: # Fallback to default font font = ImageFont.load_default() # Get text bounding box for centering bbox = draw.textbbox((0, 0), text, font=font) text_width = bbox[2] - bbox[0] text_height = bbox[3] - bbox[1] position = ((size[0] - text_width) // 2, (size[1] - text_height) // 2) # Draw text with outline for visibility outline_color = 'white' if sum(color) < 400 else 'black' for offset_x in [-2, 0, 2]: for offset_y in [-2, 0, 2]: draw.text((position[0] + offset_x, position[1] + offset_y), text, font=font, fill=outline_color) text_color = 'black' if sum(color) > 400 else 'white' draw.text(position, text, font=font, fill=text_color) # Save image os.makedirs(os.path.dirname(path), exist_ok=True) img.save(path) print(f"āœ“ Created: {path}") # Base directory base_dir = 'static/images' # Create product-specific images for 404 create_placeholder_image( f'{base_dir}/window/storm-window/404/door-white.png', '404\nDoor - White', (240, 240, 240) # Light gray ) create_placeholder_image( f'{base_dir}/window/storm-window/404/door-black.png', '404\nDoor - Black', (40, 40, 40) # Dark gray ) # Create shared images for storm windows create_placeholder_image( f'{base_dir}/window/storm-window/layers/base.jpg', 'Storm Window\nBase Layer\n(Shared)', (200, 220, 240) # Light blue ) create_placeholder_image( f'{base_dir}/window/storm-window/layers/hardware.png', 'Storm Window\nHardware\n(Shared)', (180, 180, 180) # Silver ) create_placeholder_image( f'{base_dir}/window/storm-window/layers/foreground.png', 'Storm Window\nForeground\n(Shared Plants)', (100, 180, 100) # Green ) # Create global fallback images create_placeholder_image( f'{base_dir}/layers/base.jpg', 'Global\nBase Layer\n(Fallback)', (220, 200, 180) # Beige ) print("\nāœ… All test images created successfully!") print("\nNow test the Canvas API:") print(" http://localhost:8080/api/canvas/404/base") print(" http://localhost:8080/api/canvas/404/door?color=white") print(" http://localhost:8080/api/canvas/404/hardware") print(" http://localhost:8080/api/canvas/404/foreground")