Skip to content

akshaydotweb/ascii-dither

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

ascii-dither

Python License CLI Pillow

A Python CLI tool to convert PNG images to ASCII art with multiple dithering algorithms including Floyd-Steinberg, Atkinson, and Bayer ordered dithering.

Features

  • Multiple Dithering Algorithms

    • Floyd-Steinberg - Error diffusion dithering, best for photographs
    • Atkinson - Classic Macintosh-style dithering with lighter appearance
    • Ordered (Bayer) - Matrix-based dithering with stylized halftone look
    • None - Simple brightness-to-character mapping
  • Customizable Output

    • Adjustable output width
    • Multiple character sets (detailed, simple, blocks)
    • Custom character sets support
    • Brightness inversion for dark/light terminals
  • Easy to Use

    • Simple CLI interface
    • Save output to file or print to terminal

Installation

pip install Pillow numpy

Usage

Basic Usage

python png_to_ascii.py image.png

With Dithering

# Floyd-Steinberg dithering (best for photos)
python png_to_ascii.py image.png -d floyd-steinberg

# Atkinson dithering (classic Mac style)
python png_to_ascii.py image.png -d atkinson

# Ordered/Bayer dithering (halftone effect)
python png_to_ascii.py image.png -d ordered

Adjust Width

python png_to_ascii.py image.png -w 80

Invert for Dark Backgrounds

python png_to_ascii.py image.png --invert

Save to File

python png_to_ascii.py image.png -o output.txt

Use Different Character Sets

# Detailed characters
python png_to_ascii.py image.png --charset detailed

# Simple characters
python png_to_ascii.py image.png --charset simple

# Unicode block characters
python png_to_ascii.py image.png --charset blocks

# Custom characters (darkest to lightest)
python png_to_ascii.py image.png -c "@#%*+=-:. "

Options

Option Description
-w, --width Output width in characters (default: 100)
-d, --dithering Dithering algorithm: none, floyd-steinberg, ordered, atkinson
-c, --chars Custom ASCII characters (darkest to lightest)
--charset Predefined character set: detailed, simple, blocks
--invert Invert brightness (for dark terminal backgrounds)
-l, --levels Quantization levels for Floyd-Steinberg (default: 4)
-o, --output Save output to file instead of printing

Dithering Algorithms Explained

Floyd-Steinberg

Error diffusion algorithm that distributes quantization error to neighboring pixels. Produces smooth gradients and is ideal for photographs.

     *   7/16
3/16 5/16 1/16

Atkinson

Used in early Macintosh computers. Only distributes 3/4 of the error, creating a lighter, more artistic appearance.

     *  1/8 1/8
1/8 1/8 1/8
    1/8

Ordered (Bayer)

Uses a threshold matrix to create regular dithering patterns. Produces a stylized halftone look reminiscent of print media.

Examples

Original vs Dithered

Simple (no dithering):

............::::::.....
...........:+%@@@@%+....
..........:%@@@@@@@@@-..
..........#@@****#****..

Floyd-Steinberg:

@*@*@@*@*@@*@*@@*@*@@*@*
*@@*@*@@@@*@@*@@@@*@@*@@
@@*@@*@*@*@@*@*@@*@*@@*@
@*@@@*@@@@*@@@@*@@@@*@@@

Dependencies

  • Python 3.8+
  • Pillow
  • NumPy

License

MIT License

References

About

A Python CLI tool to convert PNG images to ASCII art with multiple dithering algorithms including Floyd-Steinberg, Atkinson, and Bayer ordered dithering.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages