Skip to main content

A utility for converting images to text art.

Project description

Picharsso


A utility for converting images to text art.
PyPI - Status pypi package GitHub

Installation    |    Documentation    |    Examples    |    Contributing

Installation

Run the following command:

pip install picharsso

This will:

  • download and install the picharsso Python package (along with its dependencies).
  • create an executable, picharsso, for the CLI (command line interface).

Verification

To verify that Picharsso is installed, run:

python -c "import picharsso"

Commands

Picharsso ships with a CLI that provides some basic functionality from the terminal.

Usage

Run the following command to display a helpful message:

picharsso -h
Usage: picharsso [options] <command> [args]

  A utility for converting images to text art.

Options:
  -h, --help  Show this message and exit.

Commands:
  draw  Generate text art from an image.
  info  Displays package information.

Consider the following image:

Apple logo

Apple Computer [Rob Janoff, 1977]

To convert an image to text art, run:

picharsso draw -c -H 32 <path/to/image> gradient

Here's what it should look like:

Apple logo in text (gradient style)

Breakdown

Argument Effect
-c Apply image colors to the output text.
-H 32 Sets the number of lines of the output text to 32.
gradient Use the gradient style.

Don't forget to replace <path/to/image>.

Refer to the CLI documentation to learn about the various commands and arguments.

Library

The example from the previous section can be implemented in just a few lines of Python:

from PIL import Image
from picharsso import new_drawer

if __name__ == "__main__":
    # Open image
    image = Image.open("<path/to/image>")

    # Define drawer
    drawer = new_drawer("braille", height=32, colorize=True)

    # Print drawer output
    print(drawer(image))

Here's what it should look like:

Apple logo in text (Braille style)

Styles

Refer to the Styles documentation for an in-depth guide to the image processing behind Picharsso.

Now consider this animated GIF:

Nyan Cat

Nyan Cat

With some more lines of code, you can animate GIFs in text!

import time

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


if __name__ == "__main__":
    # Open image
    image = Image.open("<path/to/image>")

    # Get terminal height
    height, _ = terminal_size()

    # Define drawer
    drawer = new_drawer("braille", height=height, colorize=True, threshold=0)

    # Iterate over frames
    texts = []
    for frame_id in range(image.n_frames):
        # Select frame
        image.seek(frame_id)

        # Save output for frame
        texts.append(drawer(image))

    # Iterate over saved outputs in a circular manner
    num_frames = len(texts)
    counter = 0
    while True:
        # Refresh
        clear_screen()

        # Print output
        print(texts[counter])

        # Set a delay between frames
        time.sleep(1 / num_frames)

        # Circular increment
        counter = (counter + 1) % num_frames

Here's what it should look like:

Nyan Cat in text (Braille style)

Refer to the API documentation to learn about the various classes and functions.

Examples

Check out some more examples.

You can use an image directly from the web too!

Contributing

Do you have a feature request, bug report, or patch? Great! Check out the contributing guidelines!

License

Copyright (c) 2019 Kelvin DeCosta. Released under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

picharsso-2.0.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

picharsso-2.0.1-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file picharsso-2.0.1.tar.gz.

File metadata

  • Download URL: picharsso-2.0.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for picharsso-2.0.1.tar.gz
Algorithm Hash digest
SHA256 eb4d8b1a1fe6927874d02362eeb2436f86bf9b4fee02cc0ac769e8b761c1276f
MD5 db6316bf793c8b9bc543e8a3eb2add15
BLAKE2b-256 ca50550f3ef989e6dfc4346422569508ea46e11c3046d05ed08b2708d963b48e

See more details on using hashes here.

File details

Details for the file picharsso-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: picharsso-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for picharsso-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 621a1268a7f3acf2b7dd5772a267523d700c0b5d1b7341ab97838585684fa750
MD5 7303d295d4fa792b570a63e063380511
BLAKE2b-256 831a81d5a5c5957a7c4b0a30bb8ab097b62cf8d4d743c9cb0dbdedf7c9297cd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page