Skip to content

Image#

This example illustrates how to covert an image to text art.

Source

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# -*- coding: utf-8 name> -*-

"""This script converts an image to text art."""

from pathlib import Path

from PIL import Image
from picharsso import new_drawer
from picharsso.utils import terminal_size

if __name__ == "__main__":
    # Choose image
    # image_path = "<path/to/image>"
    image_path = Path(__file__).parent / "hackerman.webp"

    # Open image
    image = Image.open(image_path)

    # Choose an art style
    style = "gradient"  # or "braille"

    # Set height
    height, _ = terminal_size()

    # Define drawer
    drawer = new_drawer(style, height=height, colorize=True)

    # Print drawer output
    print(drawer(image))
Result

Consider the following image:

Hackerman

Elliot Anderson is Hackerman [u/JBisBlu]

The output of the above script should look like this:

Hackerman in text (gradient style)