Converts pictures into ASCII art
Project description
ASCII Magic
Python package that converts images into ASCII art with terminal colors. Thanks to Colorama it's compatible with the Windows terminal.
Basic usage
import ascii_magic
output = ascii_magic.from_image_file('picture.jpg')
ascii_magic.to_terminal(output)
Available functions
from_image_file()
Converts an image file into ASCII art with terminal color codes.
from_image_file(
path: str,
columns: int = 120,
width_ratio: float = 2.5,
char: str = None
) -> str
- path => a PIL-compatible file, such as picture.jpg
- columns (optional) => the number of characters per row, more columns = wider art
- pixel_width (optional) => ASCII characters are not square, so this adjusts the width to height ratio
- char (optional) => instead of using many different ASCII glyphs, you can use a single one, such as '#'
Example:
from_image_file('images/1.jpg', columns=100, width_ratio=2.6, char='@')
from_url()
As above, but using the URL of an image.
from_url(
url: str,
# ... as above
) -> str
- url => an URL which will be loaded via urllib (supports redirects)
Example:
img_url = 'https://source.unsplash.com/800x600?nature'
ascii_art = ascii_magic.from_url(img_url, columns=100)
from_image()
As above, but using an image loaded with Pillow.
from_image(
img: Image,
# ... as above
) -> str
- img => PIL image object
Example:
from PIL import Image
with Image.open('images/1.jpg') as img:
ascii_art = ascii_magic.from_image(img, columns=100)
to_terminal()
Initializes Colorama (which is required on Windows) and prints ASCII art to the terminal. It's the same as doing colorama.init()
before printing normally.
to_terminal(ascii_art: str) -> None
Licence
Copyright (c) 2020 Leandro Barone.
Usage is provided under the MIT License. See LICENSE for the full details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ascii_magic-1.1.1.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for ascii_magic-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93db82717172c4eda09938360e0b6eda26db418fca3f5b67d3eb1d519ec66231 |
|
MD5 | 072b33d3d5fffb9c7b4566bd534e3707 |
|
BLAKE2b-256 | 01ba13cab7a3df37c3bf73bd0ad9ec7aac1b87d31d9b14f77d90a2030ae1aed4 |