Skip to main content

Convert PIL images to ANSI art

Project description

Pil2ANSI

Library for converting Pillow images to ANSI art

pil2ansi3

Getting Started

Installation

pip install pil2ansi

Examples

Check out the Convert Image Example.

convert_img.py [-h] [--palette {color,grayscale,grayscale_inverted,ascii}] [--width WIDTH] [--no-alpha] img_path

Usage

Convert any PIL image to ANSI art

from PIL import Image
from pil2ansi import convert_img

# Open the image
img = Image.open("path/to/image.png")

# Convert to ANSI
ansi_img = convert_img(img)

# Print to screen
print(ansi_img) 

Palettes

There are a few palettes to choose from. To select a palette import Palettes and then pass the one you want into the convert_img function.

from PIL import Image
from pil2ansi import convert_img, Palettes

# Open the image
img = Image.open("path/to/image.png")

# Convert to ANSI
ansi_img = convert_img(img, palette=Palettes.acsii)

# Print to screen
print(ansi_img) 

The default palette is color. You can choose from color, grayscale, grayscale_inverted, and ascii.

Resizing the image

By default the image will crop to the width of your terminal widow. You can change the width of the output by passing width to convert_img. This width is the number of columns you want the image to fit in your terminal window. The aspect radio of the original image will be preserved.

from PIL import Image
from pil2ansi import convert_img

# Open the image
img = Image.open("path/to/image.png")

# Convert to ANSI
ansi_img = convert_img(img, width=100)

# Print to screen
print(ansi_img) 

Transparency

By default any part of the image with an alpha of 0 will be converted to a , rendering it transparent. You can turn this off by setting alpha to False in convert_img.

from PIL import Image
from pil2ansi import convert_img

# Open the image
img = Image.open("path/to/image.png")

# Convert to ANSI
ansi_img = convert_img(img, alpha=False)

# Print to screen
print(ansi_img) 

Development

Install all dependencies including dev dependencies by running make dev

Run tests with make test

Run mypy and black checks with make lint

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

pil2ansi-0.0.1.dev4.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

pil2ansi-0.0.1.dev4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pil2ansi-0.0.1.dev4.tar.gz.

File metadata

  • Download URL: pil2ansi-0.0.1.dev4.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for pil2ansi-0.0.1.dev4.tar.gz
Algorithm Hash digest
SHA256 2e5cc2bd87f9388f51fd1f4dbc15c2a84c589b7b189ae168a19c10a5cd330133
MD5 53626ff3e31bf0e4b7a60512b4cf1a75
BLAKE2b-256 88305ba354bd57a35a896ea9dbed06eaca2299d2c134583bc17312a0f6e2cb4a

See more details on using hashes here.

File details

Details for the file pil2ansi-0.0.1.dev4-py3-none-any.whl.

File metadata

File hashes

Hashes for pil2ansi-0.0.1.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 73b0aefb5eabb8608109bbfcb3acae4f15fb35f37bef1f3820c3cae775d2a63f
MD5 04b575c45bbb0b080aca62f43e9807ee
BLAKE2b-256 d0822f3e4e209a0f8d097b292a49e2e59bade3ac12793d1d36852262e2a53c0f

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