Skip to main content

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. Code based on ProfOak's Ascii Py.

ASCII Magic example

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


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.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ascii_magic-1.1.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file ascii_magic-1.1.3.tar.gz.

File metadata

  • Download URL: ascii_magic-1.1.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.4

File hashes

Hashes for ascii_magic-1.1.3.tar.gz
Algorithm Hash digest
SHA256 ceec6d69c6de543eae10e5423b78dc4befe30c97bf178009665019c61ad78b83
MD5 88a2ee1a989689750bcb0331c076021f
BLAKE2b-256 7fe6cf931dec0bf3aef909959d26496dd0889249e0a8e5df5f6ed3808e4d7245

See more details on using hashes here.

File details

Details for the file ascii_magic-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: ascii_magic-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.4

File hashes

Hashes for ascii_magic-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c031d61b199c180b56523b051d3bf86476da9ab118279d63ef043205aac33430
MD5 59ad4cfb2e8a92dbcdd66305c652af17
BLAKE2b-256 91d0f94010ee3b08cf1a39409086c3fd189a33edddf147b8a1530156bc37f072

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page