libasciic
A Rust library for converting images to ASCII art with optional ANSI colorization.
Features
- 🎨 Full RGB Color Support - Generate colorized ASCII art with 24-bit ANSI colors
- 🎭 Multiple Styles - Choose between foreground painting, background painting, or background-only modes
- 🔧 Customizable Character Sets - Use any character progression for brightness mapping
- 📦 Compression - Smart color compression to reduce output size
- 🖼️ Multiple Formats - Supports all image formats handled by the
imagecrate - ⚡ Flexible Resizing - Various resampling filters from nearest neighbor to Lanczos3
Installation
Add this to your Cargo.toml:
[]
= "1.0.1"
Quick Start
use File;
use ;
Examples
Basic Monochrome ASCII Art
use File;
use AsciiBuilder;
let file = open?;
let ascii = new?
.dimensions
.make_ascii?;
println!;
Colorized with Custom Character Set
use File;
use ;
let file = open?;
let ascii = new?
.dimensions
.colorize
.style
.charset?
.threshold // Reduce output size
.make_ascii?;
print!;
Background-Only Mode (Pure Color Blocks)
use File;
use ;
let file = open?;
let ascii = new?
.dimensions
.colorize
.style
.make_ascii?;
print!;
High-Quality Resampling
use File;
use ;
let file = open?;
let ascii = new?
.dimensions
.filter_type
.colorize
.make_ascii?;
print!;
API Overview
AsciiBuilder
The main builder struct for creating ASCII art. All methods are chainable.
Methods
new(image: R) -> Result<Self>- Create a new builder from an image sourcedimensions(width: u32, height: u32) -> Self- Set output dimensions (required)colorize(bool) -> Self- Enable/disable ANSI color outputstyle(Style) -> Self- Set the color stylecharset(&str) -> Result<Self>- Set custom character set for brightness mappingthreshold(u8) -> Self- Set color compression threshold (0-255)filter_type(FilterType) -> Self- Set image resampling filtermake_ascii(self) -> Result<String>- Generate the ASCII art
Style Enum
Controls how colors are applied to the output:
FgPaint- Color the characters (foreground)BgPaint- Color the background while keeping characters visibleBgOnly- Use only colored backgrounds with space characters
Character Sets
The default character set is .:-+=#@, ordered from darkest to brightest. A space character is automatically prepended for the darkest values.
Custom character sets can be provided in the same format:
.charset?
Compression Threshold
The threshold parameter controls color compression when colorization is enabled:
0- No compression (emit ANSI codes for every pixel)1-255- Only emit new color codes when the color difference exceeds this value
Higher values reduce output size but may decrease color accuracy. Recommended range: 5-20.
Tips
- Terminal characters are typically taller than they are wide, so you may want to adjust your aspect ratio accordingly
- For better quality, use
FilterType::Lanczos3orFilterType::CatmullRomwhen downscaling - Use compression (
threshold()) to significantly reduce the size of colorized output - The
BgOnlystyle works well for creating color-accurate terminal images
License
MIT
Author
S0ra (S0raWasTaken)