Skip to main content

Convert images into high-quality ASCII art — terminal, color, 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 both grayscale and color rendering 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, and ANSI-based color encoding.


Features

  • Convert images to ASCII art directly in the terminal
  • Grayscale and color rendering modes
  • HTML export — save colored ASCII art as a self-contained .html file, viewable in any browser
  • Invert mode — flip character density for clearer output on 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

    • Grayscale mode outputs plain ASCII text
    • Color mode uses ANSI escape codes to preserve pixel color in terminal output
  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
│
├── 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

From PyPI (recommended)

pip install ascii-forger

This installs the ascii-forger command globally (or into your active environment).


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 character density (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

Command-Line Arguments

Argument Description Default
image Path to input image Required
--mode Rendering mode: gray or 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 Flip character density mapping — dense chars on bright areas, sparse on dark areas 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, and --html
  • Pixel colors in color/HTML output are always the original, unmodified values

Dependencies

  • Pillow — image loading and processing

Future Enhancements

  • Edge detection mode for sharper, outline-style ASCII output
  • Real-time video and webcam ASCII rendering
  • Performance optimizations using NumPy vectorization
  • ASCII → PNG/SVG image rendering

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.1.1.tar.gz (12.7 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.1.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ascii_forger-0.1.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ascii_forger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7e9de92d3584ff5ac467eee7bb30bdaf7b6753c80d05ba8bc8d93554f838a86c
MD5 d54ed94fafb149698b4f80fc0bd2f077
BLAKE2b-256 416d7b74fedab8d6fae39b194587a01dc6bb21fadfad2b73f0684aea6ee22793

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ascii_forger-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ascii_forger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8cbcf28131d5bc3ed0e052f12d045188a83aa1cc1ed1ef18a245abaf268463c
MD5 7be5a0595ad84e1e5d7a9a321e9c37e8
BLAKE2b-256 340c57500dd7d40427e271c23d9563f7f7f8226a25cca0d274fbf3397943346c

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