ascii-magic


Nameascii-magic JSON
Version 2.3.0 PyPI version JSON
download
home_pagehttps://github.com/LeandroBarone/python-ascii_magic
SummaryConverts pictures into ASCII art
upload_time2023-02-23 02:12:21
maintainer
docs_urlNone
authorLeandro Barone
requires_python>=3.5
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ASCII Magic

Python package that converts images into ASCII art for terminals and HTML. Thanks to [Colorama](https://github.com/tartley/colorama) it's compatible with the Windows terminal.

Code based on [ProfOak's Ascii Py](https://github.com/ProfOak/Ascii_py/).

# Changelog

### v2.3 - Feb 2023
- Craiyon support: from_craiyon()

### v2.2 - Feb 2023
- Stable Diffusion support: from_stable_diffusion()

### v2.1 - Feb 2023
- DALL-E support: from_dalle()

### v2.0 - Feb 2023
- Complete rewrite, full OOP, no longer compatible with 1.x
- Added support for foreground color
- to_html()

### v1.6 - Sep 2021
- OOP functionality
- to_file()

### v1.5 - Nov 2020
- First public release

# How to install

    pip install ascii_magic

# Quickstart

```python
from ascii_magic import AsciiArt

my_art = AsciiArt.from_image('moon.jpg')
my_art.to_terminal()
```

Result:

![ASCII Magic example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_moon.png)


# The class AsciiArt

This module's entire functionality is contained within the class AsciiArt, which has a collection class methods, such as ```AsciiArt.from_image()```, that return ```AsciiArt``` objects with pictures from different sources: files, URLs, the clipboard, etc.

These objects have multiple methods, such as ```my_art.to_terminal()```, that generate ASCII art pieces from the picture. These methods have parameters such as ```columns``` that allow you to change the appearance of the art piece.

For convenience, the module ```ascii_magic``` also exposes a collection of functions with the same name as the class methods mentioned above, which do exactly the same.

Example:

```python
from ascii_magic import AsciiArt, from_image

# This:
my_art = AsciiArt.from_image('lion.jpg')
my_art.to_terminal()

# Does the same as this:
my_art = from_image('lion.jpg')
my_art.to_terminal()
```

This class is essentially a wrapper for a Pillow image. The property ```AsciiArt.image``` exposes the underlying Pillow object so you can manipulate it directly.

Example:

```python
from ascii_magic import AsciiArt
from PIL import ImageEnhance

my_art = AsciiArt.from_image('lion.jpg')
my_art.image = ImageEnhance.Brightness(my_art.image).enhance(0.2)
my_art.to_terminal()
```

## quick_test()

Loads a random Unsplash picture with the default parameters and prints it to the terminal, allowing you to verify in a single line of code that everything is running O.K.

```python
AsciiArt.quick_test() -> None
```

Example:

```python
from ascii_magic import AsciiArt

AsciiArt.quick_test()
```

## from_image()

Creates an ```AsciiArt``` object from an image file.

```python
from_image(path: str) -> AsciiArt
```

Parameters:

- ```path (str)```: an image file compatible with Pillow, such as a jpeg or png

Example:

```python
from ascii_magic import AsciiArt, Back

my_art = AsciiArt.from_image('lion.jpg')
my_art.to_terminal(columns=200, back=Back.BLUE)
```

Result:

![ASCII Magic TERMINAL mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_blue.png)

Example:

```python
from ascii_magic import AsciiArt

my_art = AsciiArt.from_image('lion.jpg')
my_art.to_html_file('ascii_art.html', columns=200, width_ratio=2)
```

Result:

![ASCII Magic HTML mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_html.png)

Example:

```python
from ascii_magic import AsciiArt

my_art = AsciiArt.from_image('lion.jpg')
my_art.to_terminal(columns=200, monochrome=True)

```

Result:

![ASCII Magic ASCII mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_ascii.png)


## from_craiyon()

Creates an ```AsciiArt``` object with [Craiyon](https://www.craiyon.com/), previously known as DALL-E Mini, a machine learning model that can generate realistic images from a description in natural language.

```python
from_craiyon(prompt: str) -> AsciiArt
```

Parameters:

- ```prompt (str)```: a description of an image in natural language

Example:

```python
from ascii_magic import AsciiArt

my_art = AsciiArt.from_craiyon('A portrait of a cow with noble clothes')
my_art.to_html_file('cow_craiyon.html', columns=200)
```

Result:

![ASCII Magic Craiyon example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_craiyon.png)

## from_dalle()

Creates an ```AsciiArt``` object with [DALL-E](https://openai.com/dall-e/), a machine learning model that can generate realistic images from a description in natural language. Requires a [DALL-E API key](https://platform.openai.com/account/api-keys). The API key can be configured in the module as described in the OpenAI documentation (```openai.api_key = api_key```) or through this function call.

```python
from_dalle(
    prompt: str,
    api_key: Optional[str]
) -> AsciiArt
```

Parameters:

- ```prompt (str)```: a description of an image in natural language
- ```api_key (str, optional)```: a DALL-E API key

Example:

```python
from ascii_magic import AsciiArt

api_key = 'SK-AFAKEDALLEAPIKEY'
my_art = AsciiArt.from_dalle('A portrait of a cow with noble clothes', api_key)
my_art.to_html_file('cow_dalle.html', columns=200)
```

Result:

![ASCII Magic DALL-E example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_dalle.png)
## from_stable_diffusion()

Creates an ```AsciiArt``` object with [Stable Diffusion](https://stability.ai/), a machine learning model that can generate realistic images from a description in natural language. Requires a [Stable Diffusion API key](https://platform.stability.ai/).

```python
from_stable_diffusion(
    prompt: str,
    api_key: str,
    steps: int = 30,
    engine: Optional[str],
) -> AsciiArt
```

Parameters:

- ```prompt (str)```: a description of an image in natural language
- ```api_key (str, optional)```: a Stable Diffusion API key
- ```steps (int, optional)```: amount of inference steps performed (see Stable Diffusion documentation)
- ```engine (str, optional)```: set the engine to use for generation (see Stable Diffusion documentation)

Example:

```python
from ascii_magic import AsciiArt

api_key = 'SK-AFAKESTABLEDIFFUSIONAPIKEY'
my_art = AsciiArt.from_stable_diffusion('A portrait of a cow with noble clothes', api_key)
my_art.to_html_file('cow_stable_diffusion.html', columns=200)
```

Result:

![ASCII Magic Stable Diffusion example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_stable_diffusion.png)

## from_url()

Creates an ```AsciiArt``` object from an image URL. Raises an ```urllib.error.URLError``` if something goes wrong while requesting the image, but you can also catch it as an ```OSError``` if you don't want to import ```urllib``` into your project.

```python
from_url(url: str) -> AsciiArt
```

Parameters:

- ```url (str)```: an URL which will be loaded via urllib (supports redirects)

Example:

```python
from ascii_magic import AsciiArt

try:
    my_art = AsciiArt.from_url('https://source.unsplash.com/800x600?nature')
except OSError as e:
    print(f'Could not load the image, server said: {e.code} {e.msg}')
my_art.to_terminal()
```

## from_clipboard()

Creates an ```AsciiArt``` object from the contents of the clipboard. Raises an ```OSError``` if the clipboard doesn't contain an image. Requires [PyGObject](https://pygobject.readthedocs.io/en/latest/getting_started.html) under Linux.

```python
from_clipboard() -> AsciiArt
```

Example:

```python
from ascii_magic import AsciiArt

try:
    my_art = AsciiArt.from_clipboard()
except OSError:
    print('The clipboard does not contain an image')
my_art.to_terminal()
```

## from_pillow_image()

Creates an ```AsciiArt``` object from an image object created with Pillow. This allows you to handle the image loading yourself.

```python
from_pillow_image(img: PIL.Image) -> AsciiArt
```

Parameters:

- ```img (obj)```: an image object created with Pillow

Example:

```python
from ascii_magic import AsciiArt
from PIL import Image

img = Image.open('lion.jpg')
my_art = AsciiArt.from_pillow_image(img)
my_art.to_terminal()
```


# The AsciiArt object

An ```AsciiArt``` object created as explained above has a collection of methods, such as ```to_ascii()```, that allows you to create and display ASCII art pieces. All of them return a string, and some have additional functionality, as described below.


## to_ascii()

Returns a string containing ASCII art and, by default, control characters that allows most terminals (also known as shells) to display color.

The module ```ascii_magic``` exposes two enums to handle color: ```Front``` and ```Back``` which allow you to select terminal-compatible colors.

```python
AsciiArt.to_ascii(
    columns: int = 120,
    width_ratio: float = 2.2,
    monochrome: bool = False,
    char: Optional[str],
    front: Optional[Front],
    back: Optional[Back]
) -> str
```

Parameters:

- ```columns (int, optional)```: the number of characters per row, more columns = wider art
- ```width_ratio (float, optional)```: ASCII characters are not squares, so this adjusts the width to height ratio during generation
- ```monochrome (bool, optional)```: if set to True, disables the usage of control characters that display color
- ```char (str, optional)```: instead of using many different ASCII glyphs, you can use a single one, such as '#'
- ```front (enum, optional)```: overrides the foreground color with one of:
  - ```Front.BLACK```
  - ```Front.RED```
  - ```Front.GREEN```
  - ```Front.YELLOW```
  - ```Front.BLUE```
  - ```Front.MAGENTA```
  - ```Front.CYAN```
  - ```Front.WHITE```
- ```back (enum, optional)```: sets the background color to one of:
  - ```Back.BLACK```
  - ```Back.RED```
  - ```Back.GREEN```
  - ```Back.YELLOW```
  - ```Back.BLUE```
  - ```Back.MAGENTA```
  - ```Back.CYAN```
  - ```Back.WHITE```

Example:

```python
from ascii_magic import AsciiArt, Back

my_art = AsciiArt.from_image('lion.jpg')
my_output = my_art.to_ascii(columns=200, back=Back.BLUE)
print(my_output)
```

Result:

![ASCII Magic TERMINAL mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_blue.png)


## to_terminal()

Identical to ```AsciiArt.to_ascii()```, but it also does a ```print()``` of the result, saving you one line of code ;)

## to_file()

Identical to ```AsciiArt.to_ascii()```, but it also saves the result to a text file.

```python
AsciiArt.to_file(
    path: str,
    # ... same parameters as AsciiArt.to_ascii()
) -> str
```
Parameters:

- ```path (str)```: the output file path

Example:

```python
from ascii_magic import AsciiArt

my_art = AsciiArt.from_image('lion.jpg')
my_art.to_file('lion.txt', monochrome=True)
```

## to_html()

Returns a string with ASCII art created as HTML markup. Accepts the same parameters as ```AsciiArt.to_ascii()```, except for ```back``` and ```front``` colors. By default the HTML ASCII art is generated with a 24-bit palette (16 million colors).

```python
AsciiArt.to_html(
    full_color: bool = True,
    # ... same parameters as AsciiArt.to_ascii(), except back and front colors
) -> str
```

Parameters:

- ```full_color (bool, optional)```: if set to False, limits color palette to 8 colors

Example:

```python
from ascii_magic import AsciiArt

my_art = AsciiArt.from_image('lion.jpg')
my_html_markup = my_art.to_html(columns=200)
```

## to_html_file()

Identical to ```AsciiArt.to_html()```, but it also saves the markup to a barebones HTML file inside a ```<pre>``` tag with a bunch of default CSS styles that you can easily open in your browser.

```python
AsciiArt.to_html_file(
    path: str,
    styles: str = '...',  # See description below
    additional_styles: str = '',
    auto_open: bool = False
    # ... same parameters as AsciiArt.to_html()
) -> str
```

Parameters:

- ```path (str)```: the output file path
- ```styles (str, optional)```: a string with a bunch of CSS styles for the ```<pre>``` element, by default:
  - display: inline-block;
  - border-width: 4px 6px;
  - border-color: black;
  - border-style: solid;
  - background-color: black;
  - font-size: 8px;
- ```additional_styles (str, optional)```: use this to add your own CSS styles without removing the default ones
- ```auto_open (bool, optional)```: if True, the file will be opened with ```webbrowser.open()```


Example:

```python
from ascii_magic import AsciiArt

my_art = AsciiArt.from_image('lion.jpg')
my_art.to_html_file('lion.html', columns=200, additional_styles='font-family: MonoLisa;')
```

Result:

![ASCII Magic HTML mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_html.png)

# Licence

Copyright (c) 2020 Leandro Barone.

Usage is provided under the MIT License. See LICENSE for the full details.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/LeandroBarone/python-ascii_magic",
    "name": "ascii-magic",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "",
    "author": "Leandro Barone",
    "author_email": "web@leandrobarone.com.ar",
    "download_url": "https://files.pythonhosted.org/packages/85/11/f578208d58bc70308df3468cedacd1e965ce23f3cec9e591f2e864ab77bc/ascii_magic-2.3.0.tar.gz",
    "platform": null,
    "description": "# ASCII Magic\n\nPython package that converts images into ASCII art for terminals and HTML. Thanks to [Colorama](https://github.com/tartley/colorama) it's compatible with the Windows terminal.\n\nCode based on [ProfOak's Ascii Py](https://github.com/ProfOak/Ascii_py/).\n\n# Changelog\n\n### v2.3 - Feb 2023\n- Craiyon support: from_craiyon()\n\n### v2.2 - Feb 2023\n- Stable Diffusion support: from_stable_diffusion()\n\n### v2.1 - Feb 2023\n- DALL-E support: from_dalle()\n\n### v2.0 - Feb 2023\n- Complete rewrite, full OOP, no longer compatible with 1.x\n- Added support for foreground color\n- to_html()\n\n### v1.6 - Sep 2021\n- OOP functionality\n- to_file()\n\n### v1.5 - Nov 2020\n- First public release\n\n# How to install\n\n    pip install ascii_magic\n\n# Quickstart\n\n```python\nfrom ascii_magic import AsciiArt\n\nmy_art = AsciiArt.from_image('moon.jpg')\nmy_art.to_terminal()\n```\n\nResult:\n\n![ASCII Magic example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_moon.png)\n\n\n# The class AsciiArt\n\nThis module's entire functionality is contained within the class AsciiArt, which has a collection class methods, such as ```AsciiArt.from_image()```, that return ```AsciiArt``` objects with pictures from different sources: files, URLs, the clipboard, etc.\n\nThese objects have multiple methods, such as ```my_art.to_terminal()```, that generate ASCII art pieces from the picture. These methods have parameters such as ```columns``` that allow you to change the appearance of the art piece.\n\nFor convenience, the module ```ascii_magic``` also exposes a collection of functions with the same name as the class methods mentioned above, which do exactly the same.\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt, from_image\n\n# This:\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_art.to_terminal()\n\n# Does the same as this:\nmy_art = from_image('lion.jpg')\nmy_art.to_terminal()\n```\n\nThis class is essentially a wrapper for a Pillow image. The property ```AsciiArt.image``` exposes the underlying Pillow object so you can manipulate it directly.\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\nfrom PIL import ImageEnhance\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_art.image = ImageEnhance.Brightness(my_art.image).enhance(0.2)\nmy_art.to_terminal()\n```\n\n## quick_test()\n\nLoads a random Unsplash picture with the default parameters and prints it to the terminal, allowing you to verify in a single line of code that everything is running O.K.\n\n```python\nAsciiArt.quick_test() -> None\n```\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\nAsciiArt.quick_test()\n```\n\n## from_image()\n\nCreates an ```AsciiArt``` object from an image file.\n\n```python\nfrom_image(path: str) -> AsciiArt\n```\n\nParameters:\n\n- ```path (str)```: an image file compatible with Pillow, such as a jpeg or png\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt, Back\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_art.to_terminal(columns=200, back=Back.BLUE)\n```\n\nResult:\n\n![ASCII Magic TERMINAL mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_blue.png)\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_art.to_html_file('ascii_art.html', columns=200, width_ratio=2)\n```\n\nResult:\n\n![ASCII Magic HTML mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_html.png)\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_art.to_terminal(columns=200, monochrome=True)\n\n```\n\nResult:\n\n![ASCII Magic ASCII mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_ascii.png)\n\n\n## from_craiyon()\n\nCreates an ```AsciiArt``` object with [Craiyon](https://www.craiyon.com/), previously known as DALL-E Mini, a machine learning model that can generate realistic images from a description in natural language.\n\n```python\nfrom_craiyon(prompt: str) -> AsciiArt\n```\n\nParameters:\n\n- ```prompt (str)```: a description of an image in natural language\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\nmy_art = AsciiArt.from_craiyon('A portrait of a cow with noble clothes')\nmy_art.to_html_file('cow_craiyon.html', columns=200)\n```\n\nResult:\n\n![ASCII Magic Craiyon example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_craiyon.png)\n\n## from_dalle()\n\nCreates an ```AsciiArt``` object with [DALL-E](https://openai.com/dall-e/), a machine learning model that can generate realistic images from a description in natural language. Requires a [DALL-E API key](https://platform.openai.com/account/api-keys). The API key can be configured in the module as described in the OpenAI documentation (```openai.api_key = api_key```) or through this function call.\n\n```python\nfrom_dalle(\n    prompt: str,\n    api_key: Optional[str]\n) -> AsciiArt\n```\n\nParameters:\n\n- ```prompt (str)```: a description of an image in natural language\n- ```api_key (str, optional)```: a DALL-E API key\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\napi_key = 'SK-AFAKEDALLEAPIKEY'\nmy_art = AsciiArt.from_dalle('A portrait of a cow with noble clothes', api_key)\nmy_art.to_html_file('cow_dalle.html', columns=200)\n```\n\nResult:\n\n![ASCII Magic DALL-E example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_dalle.png)\n## from_stable_diffusion()\n\nCreates an ```AsciiArt``` object with [Stable Diffusion](https://stability.ai/), a machine learning model that can generate realistic images from a description in natural language. Requires a [Stable Diffusion API key](https://platform.stability.ai/).\n\n```python\nfrom_stable_diffusion(\n    prompt: str,\n    api_key: str,\n    steps: int = 30,\n    engine: Optional[str],\n) -> AsciiArt\n```\n\nParameters:\n\n- ```prompt (str)```: a description of an image in natural language\n- ```api_key (str, optional)```: a Stable Diffusion API key\n- ```steps (int, optional)```: amount of inference steps performed (see Stable Diffusion documentation)\n- ```engine (str, optional)```: set the engine to use for generation (see Stable Diffusion documentation)\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\napi_key = 'SK-AFAKESTABLEDIFFUSIONAPIKEY'\nmy_art = AsciiArt.from_stable_diffusion('A portrait of a cow with noble clothes', api_key)\nmy_art.to_html_file('cow_stable_diffusion.html', columns=200)\n```\n\nResult:\n\n![ASCII Magic Stable Diffusion example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_stable_diffusion.png)\n\n## from_url()\n\nCreates an ```AsciiArt``` object from an image URL. Raises an ```urllib.error.URLError``` if something goes wrong while requesting the image, but you can also catch it as an ```OSError``` if you don't want to import ```urllib``` into your project.\n\n```python\nfrom_url(url: str) -> AsciiArt\n```\n\nParameters:\n\n- ```url (str)```: an URL which will be loaded via urllib (supports redirects)\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\ntry:\n    my_art = AsciiArt.from_url('https://source.unsplash.com/800x600?nature')\nexcept OSError as e:\n    print(f'Could not load the image, server said: {e.code} {e.msg}')\nmy_art.to_terminal()\n```\n\n## from_clipboard()\n\nCreates an ```AsciiArt``` object from the contents of the clipboard. Raises an ```OSError``` if the clipboard doesn't contain an image. Requires [PyGObject](https://pygobject.readthedocs.io/en/latest/getting_started.html) under Linux.\n\n```python\nfrom_clipboard() -> AsciiArt\n```\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\ntry:\n    my_art = AsciiArt.from_clipboard()\nexcept OSError:\n    print('The clipboard does not contain an image')\nmy_art.to_terminal()\n```\n\n## from_pillow_image()\n\nCreates an ```AsciiArt``` object from an image object created with Pillow. This allows you to handle the image loading yourself.\n\n```python\nfrom_pillow_image(img: PIL.Image) -> AsciiArt\n```\n\nParameters:\n\n- ```img (obj)```: an image object created with Pillow\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\nfrom PIL import Image\n\nimg = Image.open('lion.jpg')\nmy_art = AsciiArt.from_pillow_image(img)\nmy_art.to_terminal()\n```\n\n\n# The AsciiArt object\n\nAn ```AsciiArt``` object created as explained above has a collection of methods, such as ```to_ascii()```, that allows you to create and display ASCII art pieces. All of them return a string, and some have additional functionality, as described below.\n\n\n## to_ascii()\n\nReturns a string containing ASCII art and, by default, control characters that allows most terminals (also known as shells) to display color.\n\nThe module ```ascii_magic``` exposes two enums to handle color: ```Front``` and ```Back``` which allow you to select terminal-compatible colors.\n\n```python\nAsciiArt.to_ascii(\n    columns: int = 120,\n    width_ratio: float = 2.2,\n    monochrome: bool = False,\n    char: Optional[str],\n    front: Optional[Front],\n    back: Optional[Back]\n) -> str\n```\n\nParameters:\n\n- ```columns (int, optional)```: the number of characters per row, more columns = wider art\n- ```width_ratio (float, optional)```: ASCII characters are not squares, so this adjusts the width to height ratio during generation\n- ```monochrome (bool, optional)```: if set to True, disables the usage of control characters that display color\n- ```char (str, optional)```: instead of using many different ASCII glyphs, you can use a single one, such as '#'\n- ```front (enum, optional)```: overrides the foreground color with one of:\n  - ```Front.BLACK```\n  - ```Front.RED```\n  - ```Front.GREEN```\n  - ```Front.YELLOW```\n  - ```Front.BLUE```\n  - ```Front.MAGENTA```\n  - ```Front.CYAN```\n  - ```Front.WHITE```\n- ```back (enum, optional)```: sets the background color to one of:\n  - ```Back.BLACK```\n  - ```Back.RED```\n  - ```Back.GREEN```\n  - ```Back.YELLOW```\n  - ```Back.BLUE```\n  - ```Back.MAGENTA```\n  - ```Back.CYAN```\n  - ```Back.WHITE```\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt, Back\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_output = my_art.to_ascii(columns=200, back=Back.BLUE)\nprint(my_output)\n```\n\nResult:\n\n![ASCII Magic TERMINAL mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_blue.png)\n\n\n## to_terminal()\n\nIdentical to ```AsciiArt.to_ascii()```, but it also does a ```print()``` of the result, saving you one line of code ;)\n\n## to_file()\n\nIdentical to ```AsciiArt.to_ascii()```, but it also saves the result to a text file.\n\n```python\nAsciiArt.to_file(\n    path: str,\n    # ... same parameters as AsciiArt.to_ascii()\n) -> str\n```\nParameters:\n\n- ```path (str)```: the output file path\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_art.to_file('lion.txt', monochrome=True)\n```\n\n## to_html()\n\nReturns a string with ASCII art created as HTML markup. Accepts the same parameters as ```AsciiArt.to_ascii()```, except for ```back``` and ```front``` colors. By default the HTML ASCII art is generated with a 24-bit palette (16 million colors).\n\n```python\nAsciiArt.to_html(\n    full_color: bool = True,\n    # ... same parameters as AsciiArt.to_ascii(), except back and front colors\n) -> str\n```\n\nParameters:\n\n- ```full_color (bool, optional)```: if set to False, limits color palette to 8 colors\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_html_markup = my_art.to_html(columns=200)\n```\n\n## to_html_file()\n\nIdentical to ```AsciiArt.to_html()```, but it also saves the markup to a barebones HTML file inside a ```<pre>``` tag with a bunch of default CSS styles that you can easily open in your browser.\n\n```python\nAsciiArt.to_html_file(\n    path: str,\n    styles: str = '...',  # See description below\n    additional_styles: str = '',\n    auto_open: bool = False\n    # ... same parameters as AsciiArt.to_html()\n) -> str\n```\n\nParameters:\n\n- ```path (str)```: the output file path\n- ```styles (str, optional)```: a string with a bunch of CSS styles for the ```<pre>``` element, by default:\n  - display: inline-block;\n  - border-width: 4px 6px;\n  - border-color: black;\n  - border-style: solid;\n  - background-color: black;\n  - font-size: 8px;\n- ```additional_styles (str, optional)```: use this to add your own CSS styles without removing the default ones\n- ```auto_open (bool, optional)```: if True, the file will be opened with ```webbrowser.open()```\n\n\nExample:\n\n```python\nfrom ascii_magic import AsciiArt\n\nmy_art = AsciiArt.from_image('lion.jpg')\nmy_art.to_html_file('lion.html', columns=200, additional_styles='font-family: MonoLisa;')\n```\n\nResult:\n\n![ASCII Magic HTML mode example](https://raw.githubusercontent.com/LeandroBarone/python-ascii_magic/master/example_lion_html.png)\n\n# Licence\n\nCopyright (c) 2020 Leandro Barone.\n\nUsage is provided under the MIT License. See LICENSE for the full details.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Converts pictures into ASCII art",
    "version": "2.3.0",
    "project_urls": {
        "Homepage": "https://github.com/LeandroBarone/python-ascii_magic"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3512932518097d33785884147ccf5d3dd316fd133e514420beb82a23622a7a2b",
                "md5": "e64bdec7347c96129a5e64cf03ed9fd1",
                "sha256": "c17d562bc0dca31594b00a36392e0f2e5eb1ff42aaf5d22bf913abfa89d06fc6"
            },
            "downloads": -1,
            "filename": "ascii_magic-2.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e64bdec7347c96129a5e64cf03ed9fd1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 733178,
            "upload_time": "2023-02-23T02:12:19",
            "upload_time_iso_8601": "2023-02-23T02:12:19.291418Z",
            "url": "https://files.pythonhosted.org/packages/35/12/932518097d33785884147ccf5d3dd316fd133e514420beb82a23622a7a2b/ascii_magic-2.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8511f578208d58bc70308df3468cedacd1e965ce23f3cec9e591f2e864ab77bc",
                "md5": "f29dcf41540fe4e1bf0f07100c11cef5",
                "sha256": "3ed41a1cb167deed5ccfc628b669f35a3a03f67bdd72dcc18be5ffd8a2643d85"
            },
            "downloads": -1,
            "filename": "ascii_magic-2.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f29dcf41540fe4e1bf0f07100c11cef5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 731548,
            "upload_time": "2023-02-23T02:12:21",
            "upload_time_iso_8601": "2023-02-23T02:12:21.432133Z",
            "url": "https://files.pythonhosted.org/packages/85/11/f578208d58bc70308df3468cedacd1e965ce23f3cec9e591f2e864ab77bc/ascii_magic-2.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-23 02:12:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "LeandroBarone",
    "github_project": "python-ascii_magic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ascii-magic"
}
        
Elapsed time: 0.35039s