Convert images into ASCII art with optional ANSI truecolor support.
- Image to ASCII conversion - transforms any image into ASCII art
- ANSI truecolor support - colorized output for terminals that support 24-bit color
- Multiple charset presets -
default,dense, and Unicodeblocks - Custom charsets - define your own dark-to-light character gradient
- Aspect ratio correction - accounts for non-square terminal characters
- Luminance inversion - invert for light-on-dark or dark-on-light output
- Flexible output - print to stdout or write to a file
git clone https://github.com/SameerVers3/pixel2ascii.git
cd pixel2ascii
cargo build --releaseThe binary will be at target/release/pixel2ascii.
cargo install pixel2asciipixel2ascii <INPUT> [OPTIONS]Basic usage (grayscale, 100 characters wide):
pixel2ascii image.pngColorized output at 120 characters wide:
pixel2ascii image.png --color --width 120Use block characters for a bolder look:
pixel2ascii image.png --charset-preset blocksInvert luminance (useful for light terminals):
pixel2ascii image.png --invertSave output to a file:
pixel2ascii image.png -o output.txtCustom charset (dark → light):
pixel2ascii image.png --charset "@#%*+=-:. "| Flag / Option | Short | Default | Description |
|---|---|---|---|
<INPUT> |
required | Path to input image file | |
--width |
-w |
100 |
Maximum ASCII character width |
--aspect |
0.5 |
Character height/width ratio for aspect correction | |
--no-aspect |
Disable aspect correction (square blocks) | ||
--invert |
Invert luminance mapping | ||
--color |
-c |
Enable ANSI truecolor foreground | |
--bg |
Use background color mode (requires --color) |
||
--no-color |
Force grayscale output (overrides --color) |
||
--charset |
Custom charset ordered dark → light (≥2 chars) | ||
--charset-preset |
default |
Preset: default, dense, or blocks |
|
--output |
-o |
Write output to file instead of stdout | |
--quiet |
Suppress non-error messages | ||
--help |
-h |
Show help | |
--version |
-V |
Show version |
| Preset | Characters |
|---|---|
default |
@%#*+=-:. |
dense |
@M#W$9876543210?!abc;:+=-,._ |
blocks |
█▓▒░ (Unicode block elements) |
- Load image - uses the
imagecrate to decode PNG, JPEG, GIF, BMP, etc. - Compute block size - divides the image into blocks based on target width and aspect ratio.
- Sample blocks - computes average RGB and luminance for each block.
- Match characters - maps luminance to the appropriate character from the charset.
- Render - outputs plain text or ANSI-colored text depending on flags.
L = 0.2126 × R + 0.7152 × G + 0.0722 × B
This is the standard Rec. 709 luminance formula.
pixel2ascii/
├── Cargo.toml
├── README.md
└── src/
├── main.rs # CLI entry point
├── lib.rs # Library exports
├── cli.rs # Clap-based argument parsing
├── image.rs # Image loading and block sampling
├── font.rs # Charset bitmap generation (font8x8)
└── ascii.rs # ASCII rendering logic
| Crate | Purpose |
|---|---|
clap |
Command-line argument parsing |
image |
Image decoding (PNG, JPEG, etc.) |
font8x8 |
8×8 bitmap font for charset intensity calculation |
MIT © Sameer
Contributions are welcome! Please open an issue or submit a pull request.
Made with ❤️ in Rust