Metadata-Version: 2.1
Name: pil2ansi
Version: 0.0.1.dev3
Summary: Convert PIL images to ANSI art
Author-email: lostways <andrew@lostways.com>
License: MIT License
        
        Copyright (c) 2023 Andrew Lowe
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/lostways/pil2ansi
Keywords: pil,pillow,ansi,art,image,terminal
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pillow
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: mypy; extra == "dev"

# Pil2ANSI
Library for converting Pillow images to ANSI art

![pil2ansi](https://github.com/lostways/pil2ansi/assets/1101232/a262483b-674b-4271-a072-1948758ae5f8)

# Getting Started

## Installation
```
pip install pil2ansi
```

## Examples
Check out the [Convert Image Example](examples/convert_img.py).
```
convert_img.py [-h] [--palette {color,grayscale,grayscale_inverted,ascii}] [--width WIDTH] [--alpha ALPHA] img_path
```

# Usage

## Convert any PIL image to ANSI art
```python
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.

```python
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.

```python
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`.

```python
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`
