Image to ASCII Converter


Generated ASCII Art

No file chosen

Python Code

from PIL import Image

def image_to_ascii(image, width=100):
    ascii_chars = "@%#*+=-:. "
    aspect_ratio = image.height / image.width
    new_height = int(aspect_ratio * width * 0.55)
    img_resized = image.resize((width, new_height))
    img_gray = img_resized.convert("L")
    pixels = img_gray.getdata()
    ascii_str = "".join(ascii_chars[pixel * len(ascii_chars) // 256] for pixel in pixels)
    ascii_rows = [ascii_str[i:i+width] for i in range(0, len(ascii_str), width)]
    return ascii_rows