Skip to main content

A lightweight module to generate colorful ascii art from images

Project description

img2text

A lightweight module to generate colorful ascii art from images

To install img2text:

pip install img2text 

How To Use

Let's use the python logo as reference:

Python Logo

To generate an ascii image

from img2text import img_to_ascii

ascii_img = img_to_ascii('data/python.png', width=80)
print(ascii_img)

We obtain the following:

First Generated Image

Adding Color

We can customize this further by adding color (to be shown in the console):

from img2text import img_to_ascii

ascii_img = img_to_ascii('data/python.png', width=80, colorful=True)
print(ascii_img)

We obtain the following:

Second Generated Image

Customizing Output

We can reverse the intensity of the image by setting reverse to True

from img2text import img_to_ascii

ascii_img = img_to_ascii('data/python.png', width=80, colorful=True, reverse=True)
print(ascii_img)

We obtain the following:

Third Generated Image

We can get a slightly brighter image by adding the bright option which sets the characters to bold:

from img2text import img_to_ascii

ascii_img = img_to_ascii('data/python.png', width=80, colorful=True, reverse=True, bright=True)
print(ascii_img)

We obtain the following:

Fourth Generated Image

You can also change the character set by providing a custom string of characters that increase in intensity:

from img2text import img_to_ascii

chars = r" ░▒▓█"

ascii_img = img_to_ascii('data/python.png', width=80, colorful=True, bright=True, chars=chars)
print(ascii_img)

We obtain the following:

Fourth Generated Image

Exporting ASCII image to a file

It's also possible to export the result to a text file, so you can print its content using the cat command for example To do this all you need to do is to write the content to a file:

from img2text import img_to_ascii

ascii_img = img_to_ascii('data/python.png', width=80, colorful=True)

with open('logo.ascii', 'w') as f:
    f.write(ascii_img + '\n')

or using the CLI:

img2text -cw 80 -o logo.ascii data/python.png

Additional Options

  • Customize the width and height by providing the number of columns/lines to use
  • Customize the aspect ratio by providing ar_coef coefficient. The default value is set to 2.4 but depending on the console you are using it might be interesting to try out values from [2, 3]
  • You can add a Background Color by setting bg_color to one of the following values:
    • BLACK
    • RED
    • GREEN
    • YELLOW
    • BLUE
    • MAGENTA
    • CYAN
    • WHITE

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

img2text-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

img2text-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file img2text-0.1.0.tar.gz.

File metadata

  • Download URL: img2text-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for img2text-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6617d663294ac42211411b83d74e6fe65fa36748704ff9bf319160509656f33a
MD5 5360e01c842528ef724ad57c317a7c0e
BLAKE2b-256 8b951dac6bc393998e136faef9b2ae4972dc8980af18db1c8d71e71e4da0d666

See more details on using hashes here.

File details

Details for the file img2text-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: img2text-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for img2text-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5b1c5d8e1bf54d7ba509ab13234d6556fbcb2379e2322ad3e73160dd7ed812f
MD5 26a3f22cdb67f9e02d68d8820a4ff52d
BLAKE2b-256 873d860019c29de79ba56aa43e98cc160b433a41e71226bae90d5bdf625c3204

See more details on using hashes here.

Supported by

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