🛠️ToolsShed

이미지 → ASCII 아트 변환기

이미지를 ASCII 아트로 변환합니다.

여기를 클릭하거나 이미지를 드래그하세요

자주 묻는 질문

코드 구현

from PIL import Image

CHARS = "@#S%?*+;:,. "

def image_to_ascii(path, width=80):
    img = Image.open(path).convert("L")
    w, h = img.size
    aspect = h / w
    new_h = int(width * aspect * 0.45)  # correct for char ratio
    img = img.resize((width, new_h))
    pixels = img.getdata()
    lines = []
    for i in range(0, len(pixels), width):
        row = pixels[i:i + width]
        line = "".join(CHARS[int(p / 255 * (len(CHARS) - 1))]
                       for p in row)
        lines.append(line)
    return "\n".join(lines)

print(image_to_ascii("input.jpg", width=100))

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.