import cv2
import numpy as np

def img_to_ascii(img_path, target_width=120):
    img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
    if img is None:
        print("Could not load image:", img_path)
        return
        
    h, w = img.shape
    aspect_ratio = h / w
    # Terminal characters are roughly 2:1 height:width, so adjust aspect
    target_height = int(target_width * aspect_ratio * 0.5)
    
    resized = cv2.resize(img, (target_width, target_height))
    
    # ASCII characters gradient from dark to light
    chars = ["@", "%", "#", "*", "+", "=", "-", ":", ".", " "]
    
    # Normalize mapping
    for y in range(target_height):
        row_str = ""
        for x in range(target_width):
            pixel = resized[y, x]
            # Map 0-255 to 0-9
            char_idx = int((pixel / 255.0) * 9)
            row_str += chars[char_idx]
        print(row_str)

if __name__ == "__main__":
    print("=== debug_chunk_0.png ===")
    img_to_ascii("C:/Users/Certes/.gemini/antigravity/brain/975cea00-dd68-4689-9ee3-f1a2408b4ee6/debug_chunk_0.png", 120)
