Skip to main content

Converts pictures into ASCII art

Project description

ASCII Magic

Python package that converts images into ASCII art. Requires colorama and PIL.

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_image()

As above, but using an image loaded with Pillow.

from_image(
    img:Image,
    # ... as above
) -> str
  • img => PIL image

Example:

import ascii_magic
from PIL import Image
img = Image.open('images/1.jpg')
ascii_art = ascii_magic.from_image_file(img, columns=100)
img.close()

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


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.0.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

ascii_magic-1.0.0-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

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