Skip to main content

Convert images into ASCII art — terminal, color, braille Unicode, HTML export, and invert mode.

Project description

ASCII Forger

PyPI version Python 3.8+ License: MIT

ASCII Forger is a terminal-based ASCII rendering engine that converts images into high-fidelity ASCII art. It supports grayscale, color, and braille Unicode rendering modes and is designed as a modular, extensible command-line tool.

The project focuses on bridging image processing concepts with terminal rendering, providing a practical implementation of pixel-to-character mapping, perceptual brightness scaling, ANSI-based color encoding, and Unicode braille dot rendering.


Features

  • Convert images to ASCII art directly in the terminal
  • Grayscale and color rendering modes
  • Braille Unicode mode — 4× effective resolution using Unicode dot-matrix characters (⣿⠿⡇)
  • HTML export — save colored ASCII art as a self-contained .html file, viewable in any browser
  • Invert mode — flip pixel colors for a photo-negative effect, ideal for light-background subjects
  • Adjustable output width for resolution control
  • File output support (plain text / ANSI)
  • Modular and extensible architecture
  • CLI-based usage with argument parsing

How It Works

The system follows a structured pipeline:

  1. Image Loading The input image is loaded using Pillow.

  2. Resizing The image is resized while maintaining aspect ratio. A correction factor is applied to account for non-square terminal characters.

  3. Grayscale Conversion (optional) For grayscale mode, the image is converted using luminance weighting.

  4. Pixel Mapping Each pixel is mapped to an ASCII character based on its intensity.

  5. Rendering

    • gray — standard ASCII, brightness → character density, grayscale output
    • color — standard ASCII with ANSI true-color per character
    • braille — each 2×4 pixel block is encoded as a Unicode braille character (U+2800U+28FF), achieving ~4× spatial resolution per terminal column
    • braille-color — braille dot encoding with ANSI true-color (average RGB of each block)
  6. HTML Export (optional) Each character is wrapped in a <span style="color:rgb(...)"> tag, producing a pixel-accurate, browser-renderable HTML file with no external dependencies.


Project Structure

ascii-forge/
│
├── ascii_forge/           # Main package
│   ├── __init__.py
│   ├── main.py
│   ├── image_loader.py
│   ├── processor.py
│   ├── ascii_mapper.py
│   ├── renderer.py
│   ├── html_exporter.py
│   └── braille_mapper.py  # Braille Unicode renderer (new in v0.2.0)
│
├── assets/            # Local test images (ignored by Git)
├── outputs/           # Generated outputs (ignored by Git)
│
├── pyproject.toml     # Package configuration (PyPI-ready)
├── requirements.txt
├── README.md
└── SETUP.md

Installation

Recommended — pipx (for CLI tools)

pipx installs CLI tools into isolated environments and automatically adds the command to your PATH — no venv activation, no PATH fiddling required.

# Install pipx if you don't have it
pip install pipx
pipx ensurepath

# Then install ascii-forger
pipx install ascii-forger

After that, ascii-forger works in any terminal, anywhere on your system.

Upgrade to a new version:

pipx upgrade ascii-forger

Alternative — pip install

pip install ascii-forger

Note for Windows users: If the ascii-forger command is not found after pip install, your Python Scripts\ directory may not be on your PATH. Either use pipx (above) or add %APPDATA%\Python\Python3XX\Scripts to your system PATH manually.

Upgrade to a new version:

pip install --upgrade ascii-forger

From Source (for development)

Clone the repository:

git clone https://github.com/ArshSharan/Ascii-Forge.git
cd Ascii-Forge

Create and activate a virtual environment:

python -m venv .venv
.venv\Scripts\activate

Install in editable mode:

pip install -e .

Uses pyproject.toml for packaging (PEP 517/518 compliant).


Usage

Basic usage:

ascii-forger path/to/image.jpg

Color rendering:

ascii-forger path/to/image.jpg --mode color

Custom width:

ascii-forger path/to/image.jpg --width 150

Save output to file:

ascii-forger path/to/image.jpg --output output.txt

Export as HTML (browser-viewable, colored):

ascii-forger path/to/image.jpg --html outputs/art.html

HTML export with custom width:

ascii-forger path/to/image.jpg --width 150 --html outputs/art.html

Full example (terminal render + HTML export simultaneously):

ascii-forger path/to/image.jpg --mode color --width 120 --output output.txt --html outputs/art.html

Invert colors (photo-negative, great for light-background portraits):

ascii-forger path/to/image.jpg --invert

Invert with HTML export:

ascii-forger path/to/image.jpg --invert --html outputs/inverted.html

Braille Unicode rendering (4× resolution, grayscale):

ascii-forger path/to/image.jpg --mode braille --width 80

Braille with true-color:

ascii-forger path/to/image.jpg --mode braille-color --width 100

Braille + invert + HTML export:

ascii-forger path/to/image.jpg --mode braille --invert --html outputs/braille.html

Command-Line Arguments

Argument Description Default
image Path to input image Required
--mode gray | color | braille | braille-color gray
--width Output width in characters 100
--output File path to save plain-text / ANSI output None
--html File path to save a self-contained HTML export (e.g. outputs/art.html) None
--invert Invert pixel colors before rendering (photo-negative). Works with all modes. Off

Notes on Color Output

Color mode uses ANSI escape sequences. As a result:

  • Output files will contain ANSI codes
  • Standard text editors may not render colors
  • Terminal environments that support ANSI will display colors correctly

Notes on HTML Export

  • The --html flag produces a self-contained HTML file — no internet connection or external assets required
  • Colors are embedded as inline rgb() styles, so the output is fully portable
  • The file can be opened in any modern browser
  • Parent output directories are created automatically if they don't exist
  • HTML export is independent of --mode; it always uses the full-color pixel data

Notes on Invert Mode

--invert flips the character density mapping only — it does not alter pixel colors:

  • Without invert: dark pixel → dense char (@), bright pixel → sparse char ( )
  • With invert: bright pixel → dense char (@), dark pixel → sparse char ( )
  • This makes light-background subjects (e.g. portraits with white backgrounds) appear much more defined
  • Works with all modes: gray, color, braille, braille-color, and --html
  • Pixel colors in color/HTML output are always the original, unmodified values

Notes on Braille Mode

Braille mode (--mode braille / --mode braille-color) uses Unicode characters from the Braille Patterns block (U+2800U+28FF):

  • Each braille character encodes a 2×4 pixel block (8 individual dots) → ~4× the spatial resolution of standard ASCII
  • braille — grayscale dot mapping; each pixel above a brightness threshold becomes a lit dot
  • braille-color — same dot mapping but each character is ANSI-colored with the average RGB of its 2×4 block
  • --invert flips the threshold so dark pixels become lit dots (useful for dark subjects on light backgrounds)
  • --html exports a braille HTML file; the browser font stack includes Segoe UI Symbol (Windows), Noto Sans Mono (Linux), and Apple Symbols (macOS) to guarantee correct rendering

Dependencies

  • Pillow — image loading and processing

Future Enhancements

  • Custom character set support (--chars) for power users
  • Edge detection mode for sharper, outline-style ASCII output
  • Python importable API (from ascii_forge import to_ascii, to_braille)
  • GIF → Animated HTML export (play ASCII art in any browser)
  • Image export — save ASCII art directly as a PNG, JPEG, or SVG file
  • Performance optimizations using NumPy vectorization

License

This project is open-source and available under the MIT License.


Author

Arsh Sharan

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_forger-0.2.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

ascii_forger-0.2.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file ascii_forger-0.2.1.tar.gz.

File metadata

  • Download URL: ascii_forger-0.2.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ascii_forger-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1c9dd60dfbfefbc8976d430a23389fb9c7b7a677d1bcbd59e5a2effa0256dac8
MD5 5af5fe948e7c821db28b1354d8a2c8f4
BLAKE2b-256 c0c3e858eb4f40f18c8ab00410709736bce481eca2e177bb538fd61bf390484f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_forger-0.2.1.tar.gz:

Publisher: publish.yml on ArshSharan/Ascii-Forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ascii_forger-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ascii_forger-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ascii_forger-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a78a7bad2658b95769c7cdeb80707e06acb7a5884cf70b5d6113bff732f0a937
MD5 1266b241d95a6d4f52bbcd38149450a2
BLAKE2b-256 4063232ceddf6e622ecf46bb95817a46df9cefacbdec64d8ba42a5f06e34ff25

See more details on using hashes here.

Provenance

The following attestation bundles were made for ascii_forger-0.2.1-py3-none-any.whl:

Publisher: publish.yml on ArshSharan/Ascii-Forge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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