πŸ› οΈToolsShed

Gambar ke Seni ASCII

Mengubah gambar apa pun menjadi seni ASCII yang dapat dikustomisasi.

Klik atau seret gambar ke sini

Pertanyaan yang Sering Diajukan

Implementasi Kode

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.