| Crates.io | monochora |
| lib.rs | monochora |
| version | 0.1.8 |
| created_at | 2025-05-25 10:15:25.878256+00 |
| updated_at | 2025-06-27 07:25:52.656231+00 |
| description | gif to ascii art converter written in rust |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1688249 |
| size | 543,985 |
Monochora is a GIF to ASCII art converter written in Rust. It can transform GIF animations into playable ASCII animations in your terminal or save them as ASCII art files or even convert them back to colored GIF animations with ASCII characters.
The easiest way to install Monochora is using Cargo:
cargo install monochora
Make sure you have Rust and Cargo installed. If not, install it from rust-lang.org.
Clone the repository:
git clone https://github.com/ralphmodales/monochora.git
cd monochora
Build and install:
cargo install --path .
Or just build without installing:
cargo build --release
If you chose to just build, the binary will be available at target/release/monochora
# Basic usage with local file (plays in terminal)
monochora -i input.gif
# Basic usage with URL - downloads and converts automatically
monochora -i https://example.com/animation.gif
# Control animation speed - play at half speed
monochora -i input.gif --speed 0.5
# Control animation speed - play at double speed
monochora -i input.gif --speed 2.0
# Set target frames per second
monochora -i input.gif --fps 30
# Save as ASCII text file with dithering
monochora -i input.gif -s --dither atkinson
# Save as ASCII text file
monochora -i input.gif -s
# Save to specific output file
monochora -i input.gif -o my_ascii.txt
# Generate colored ASCII in terminal
monochora -i input.gif -c
# Download from URL and generate colored ASCII with speed control
monochora -i "https://giffiles.alphacoders.com/220/220890.gif" -c -w 200 -H 100 --speed 1.5
# Invert brightness
monochora -i input.gif -v
# Use simple character set
monochora -i input.gif -p
# Use custom character set (inline)
monochora -i input.gif --charset " ·∘○●◉"
# Use custom character set from file
monochora -i input.gif --charset-file ./my-chars.txt
# List available character sets
monochora --list-charsets
# List available dithering algorithms
monochora --list-dithering
# Save as high-quality ASCII GIF animation with speed adjustment and dithering
monochora -i input.gif --gif-output output.gif --speed 0.8 --dither stucki
# Save as high-quality ASCII GIF animation with speed adjustment
monochora -i input.gif --gif-output output.gif --speed 0.8
# Generate GIF with default name and target FPS
monochora -i input.gif --gif-output --fps 24
# Custom width (height calculated automatically to preserve aspect ratio)
monochora -i input.gif -w 100
# Custom width and height
monochora -i input.gif -w 100 -H 50
# Scale the original dimensions (0.5 = half size, 2.0 = double size)
monochora -i input.gif --scale 0.5
# Fit to terminal width
monochora -i input.gif --fit-terminal
# Disable aspect ratio preservation
monochora -i input.gif -w 100 --preserve-aspect false
# White text on black background for GIF output with slow motion
monochora -i input.gif --gif-output output.gif --white-on-black --speed 0.3
# Black text on white background for GIF output
monochora -i input.gif --gif-output output.gif --black-on-white
# Custom font size for GIF output (optimized palettes)
monochora -i input.gif --gif-output output.gif --font-size 20
# High-performance processing with custom thread count and speed control
monochora -i input.gif --threads 8 --fps 60
# Quiet mode for batch processing
monochora -i input.gif -q --gif-output output.gif
# Debug with detailed logging
monochora -i input.gif --log-level debug
# Download from URL and save as high-quality ASCII GIF with speed control
monochora -i "https://example.com/cool.gif" --gif-output result.gif --black-on-white --font-size 16 --speed 1.2
Options:
-i, --input <INPUT> Input GIF file path or URL (supports HTTP/HTTPS)
-o, --output <OUTPUT> Output file path for text files
-w, --width <WIDTH> Target width in characters
-H, --height <HEIGHT> Target height in characters
-c, --colored Use colored ASCII (ANSI colors)
-v, --invert Invert brightness
-p, --simple Use simple character set
-s, --save Save to text file instead of playing
--gif-output [<GIF_OUTPUT>] Output as ASCII GIF file (optional path)
--font-size <FONT_SIZE> Font size for GIF output [default: 14.0]
--white-on-black White text on black background for GIF
--black-on-white Black text on white background for GIF
--speed <SPEED> Animation speed multiplier (0.1-10.0, where 1.0 = original speed)
--fps <FPS> Target frames per second (1-120)
--fit-terminal Fit ASCII art to terminal width
--scale <SCALE> Scale factor for original dimensions
--preserve-aspect <PRESERVE_ASPECT> Preserve original aspect ratio [default: true]
--threads <THREADS> Number of threads for parallel processing
--charset <CHARSET> Custom character set string (ordered darkest to lightest)
--charset-file <CHARSET_FILE> Path to custom character set file
--list-charsets List available character sets and exit
--list-dithering List available dithering algorithms and exit
--dither <DITHER> Dithering algorithm (none, floyd-steinberg, atkinson, jarvis, stucki, burkes, sierra, two-row-sierra, sierra-lite)
--responsive Enable responsive mode - auto-adjust when terminal is resized
--watch-terminal Watch terminal for resize events (requires responsive mode)
-q, --quiet Suppress progress output
--log-level <LOG_LEVEL> Log level (error, warn, info, debug, trace) [default: info]
-h, --help Print help
-V, --version Print version
Monochora supports multiple dithering algorithms to improve the quality of ASCII art by reducing visual artifacts and enhancing detail preservation. Dithering spreads quantization errors across neighboring pixels, resulting in smoother gradients and better visual fidelity.
# Use Floyd-Steinberg dithering for general-purpose quality
monochora -i input.gif --dither floyd-steinberg
# Atkinson dithering for high-contrast images
monochora -i high_contrast.gif --dither atkinson -c
# Jarvis dithering for smooth gradients in detailed images
monochora -i landscape.gif --dither jarvis --gif-output output.gif
# Sierra-Lite for fast processing with decent quality
monochora -i animation.gif --dither sierra-lite --speed 1.5
# List all available dithering algorithms
monochora --list-dithering
Monochora provides flexible animation speed control through two mutually exclusive options:
--speed)Control animation playback speed with a multiplier:
--speed 0.5 - Half speed (slower, more detailed viewing)--speed 2.0 - Double speed (faster playback)--speed 0.25 - Quarter speed (very slow for detailed analysis)--speed 5.0 - Five times faster--fps)Set a specific target frame rate:
--fps 30 - Standard video frame rate--fps 60 - Smooth high frame rate--fps 12 - Cinematic slow motion effect--fps 120 - Ultra-smooth playback# Slow motion for detailed viewing
monochora -i fast_animation.gif --speed 0.3 -c
# Speed up a slow GIF
monochora -i slow_animation.gif --speed 3.0
# Set consistent 24 FPS for cinematic feel
monochora -i variable_fps.gif --fps 24 --gif-output cinema.gif
# Ultra-smooth 60 FPS terminal playback
monochora -i animation.gif --fps 60 -c --fit-terminal
# Very slow analysis mode
monochora -i complex_animation.gif --speed 0.1 -w 150
# Fast preview mode
monochora -i long_animation.gif --speed 8.0 --simple
# Combine with other features for optimal viewing
monochora -i "https://example.com/animation.gif" --speed 1.5 -c -w 120 --charset " ·∘○●"
Monochora can adapt to terminal size changes during playback for optimal viewing:
--responsive)Enables automatic adjustment of ASCII art dimensions when terminal size changes:
--watch-terminal)Actively monitors terminal for resize events in real-time:
--responsive mode# Basic responsive mode - adapts when terminal is manually resized
monochora -i animation.gif --responsive -c
# Active terminal monitoring with speed control
monochora -i animation.gif --responsive --watch-terminal --speed 0.8
# Responsive colored output with custom character set
monochora -i animation.gif --responsive --watch-terminal -c --charset " ·∘○●"
# Responsive mode with FPS control
monochora -i animation.gif --responsive --fps 30 --fit-terminal
Monochora offers flexible character set options for different artistic styles and use cases:
--simple): .:-=+*#%@ - Basic 10-character set for clean, fast conversionCreate your own character palettes for specialized needs:
# Artistic styles
monochora -i art.gif --charset " ·∘○●◉" # Geometric circles
monochora -i photo.jpg --charset " ░▒▓█" # Block characters
monochora -i sketch.gif --charset " .-+*#" # Technical style
# Cultural/linguistic
monochora -i anime.gif --charset "・〆ヲァィヵヶ" # Japanese characters
monochora -i mandala.gif --charset " ༄༅༆༇༈" # Tibetan symbols
# Specialized applications
monochora -i xray.png --charset " .-+*#%@@" # Medical imaging
monochora -i diagram.gif --charset "⠀⠁⠂⠃⠄⠅⠆⠇" # Braille patterns
Store reusable character sets in text files:
# Create a character set file
echo " .-+*#%@@" > density.txt
monochora -i image.gif --charset-file density.txt
# Organize sets by category
mkdir palettes
echo " ·∘○●◉" > palettes/geometric.txt
echo " ༄༅༆༇༈" > palettes/tibetan.txt
monochora -i input.gif --charset-file palettes/geometric.txt
Use --list-charsets to see examples and usage:
monochora --list-charsets
Monochora enforces exclusive output modes to avoid conflicts:
--save or --output <file>--gif-output [path]You cannot combine multiple output modes in a single command.
Character set options are mutually exclusive:
--simple (default uses detailed set)--charset "characters"--charset-file path.txtYou cannot combine multiple character set options in a single command.
Speed control options are mutually exclusive:
--speed <multiplier> (0.1-10.0)--fps <frame_rate> (1-120)You cannot use both --speed and --fps in the same command.
--responsive only works with terminal display mode--save, --output, --gif-output)--watch-terminal requires --responsive mode to be enabled--white-on-black and --black-on-white can only be used with --gif-output--fit-terminal only works with terminal display mode--save, --output, --gif-output)--font-size only applies to GIF output modeMonochora is optimized for high-performance processing:
# Use all CPU cores for maximum speed with fast playback
monochora -i large_animation.gif --threads 16 --gif-output result.gif --speed 2.0
# Quiet batch processing with speed control
monochora -i input.gif -q --gif-output output.gif --font-size 12 --fps 30
# High-performance colored terminal output with smooth 60 FPS
monochora -i animation.gif -c --threads 8 --fps 60
# Debug mode with detailed logging and slow motion
monochora -i animation.gif --log-level debug --threads 4 --speed 0.5
The ASCII GIF output feature includes several advanced optimizations:
# High-quality small text with slow motion (more colors, precision quantization)
monochora -i input.gif --gif-output high_quality.gif --font-size 8 --speed 0.4
# Optimized medium text with standard cinema FPS (balanced quality/performance)
monochora -i input.gif --gif-output medium.gif --font-size 14 --fps 24
# Fast large text with accelerated playback (fewer colors, optimized for speed)
monochora -i input.gif --gif-output large.gif --font-size 24 --speed 3.0
# Custom styling with adaptive palettes and speed control
monochora -i input.gif --gif-output custom.gif --black-on-white --font-size 16 --fps 30
# Auto-generated output filename with speed adjustment
monochora -i my_animation.gif --gif-output --speed 1.5 # Creates ascii_my_animation.gif
To play an animation in your terminal:
monochora -i animation.gif
Press q or Esc to exit the animation.
Control animation playback speed for different viewing experiences:
# Slow motion for detailed analysis
monochora -i complex_animation.gif --speed 0.25 -c -w 150
# Speed up slow animations
monochora -i slow_gif.gif --speed 4.0 --fit-terminal
# Set consistent frame rate for smooth playback
monochora -i variable_speed.gif --fps 30 -c
# Ultra-smooth high frame rate display
monochora -i animation.gif --fps 60 --charset " ·∘○●"
# Cinematic 24 FPS with custom styling
monochora -i movie_clip.gif --fps 24 --charset " .-=+*#" -w 120
Explore different artistic styles with custom character sets:
# Minimalist density gradient with speed control
monochora -i portrait.gif --charset " .oO@" --speed 0.8
# Geometric progression with smooth FPS
monochora -i abstract.gif --charset " ·∘○●◉" -c --fps 45
# Technical documentation style with slow playback
monochora -i diagram.png --charset " .-=+*#" -w 120 --speed 0.5
# High-contrast for readability with fast preview
monochora -i screenshot.gif --charset " ░▓█" --fit-terminal --speed 3.0
# Artistic braille output with controlled timing
monochora -i pattern.gif --charset "⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋" --save --fps 20
Download and play a GIF from the internet:
# Simple terminal playback with speed control
monochora -i "https://media.giphy.com/media/3o7abKhOpu0NwenH3O/giphy.gif" --speed 1.5
# Colored ASCII with custom dimensions, character set, and FPS
monochora -i "https://example.com/animation.gif" -c -w 150 -H 75 --charset " ·∘○●" --fps 30
# Download and save as high-quality ASCII GIF with speed adjustment
monochora -i "https://example.com/source.gif" --gif-output converted_ascii.gif --speed 0.7
# Standard colored output
monochora -i animation.gif -c
# Colored output with speed control
monochora -i animation.gif -c --fps 45
Scale the animation to half size while preserving aspect ratio:
# Basic scaling
monochora -i animation.gif --scale 0.5
# Scaling with speed control
monochora -i animation.gif --scale 0.5 --speed 2.0
Make the animation fit your terminal width:
# Basic terminal fitting
monochora -i animation.gif --fit-terminal
# Terminal fitting with speed control
monochora -i animation.gif --fit-terminal --fps 60
The dimension system now properly accounts for character aspect ratios:
# Width-based scaling (height calculated for proper proportions)
monochora -i animation.gif -w 120
# Height-based scaling (width calculated for proper proportions)
monochora -i animation.gif -H 40
# Exact dimensions with speed control (may distort aspect ratio)
monochora -i animation.gif -w 120 -H 40 --preserve-aspect false --speed 1.3
# Save with default filename
monochora -i animation.gif -s
# Save to specific file with speed adjustment (affects timing comments if included)
monochora -i animation.gif -o my_ascii_art.txt --speed 2.0
# Save with custom character set and FPS control
monochora -i animation.gif -s --charset " ░▒▓█" --fps 24
# Default output filename (ascii_animation.gif) with speed control
monochora -i animation.gif --gif-output --speed 1.2
# Custom output filename with character set and FPS
monochora -i animation.gif --gif-output my_ascii.gif --charset " ·∘○●" --fps 30
# High-quality output with custom styling, character set, and speed control
monochora -i animation.gif --gif-output result.gif --black-on-white --font-size 18 --charset " .-+*#" --speed 0.8
# Performance-optimized batch processing with FPS control
monochora -i animation.gif --gif-output result.gif --quiet --threads 12 --fps 30
Create a large, detailed ASCII GIF with optimized processing:
# Large scale with speed control
monochora -i small_animation.gif --gif-output large_result.gif --scale 2.0 --font-size 8 --threads 8 --speed 1.5
# High quality with smooth FPS
monochora -i input.gif --gif-output quality_result.gif --scale 1.8 --font-size 10 --fps 45
Monochora includes comprehensive input validation:
Monochora supports downloading GIFs directly from URLs:
# Download and convert a GIF from Giphy with speed control
monochora -i "https://media.giphy.com/media/example/giphy.gif" -c --speed 1.8
# Download from any image hosting service with FPS control
monochora -i "https://i.imgur.com/example.gif" -w 100 --fps 30
# Works with direct links to GIF files with speed adjustment
monochora -i "https://example.com/path/to/animation.gif" --gif-output result.gif --speed 0.6
Monochora offers intelligent dimension control with proper character aspect ratio handling:
# Preserve image proportions with character scaling and speed control
monochora -i wide_image.gif -w 160 --speed 1.3 # Height auto-calculated
# Scale with proper character proportions and FPS control
monochora -i image.gif --scale 1.5 --fps 30 # 150% size with character correction
# For GIF output, dimensions are calculated for target pixel size with speed adjustment
monochora -i input.gif --gif-output result.gif -w 800 --font-size 12 --speed 0.8
Monochora can also be used as a library in your Rust projects:
use monochora::{
converter::{image_to_ascii, image_to_ascii_with_dithering, AsciiConverterConfig, DitheringAlgorithm},
handler::decode_gif,
display::display_ascii_animation,
output::{ascii_frames_to_gif_with_dimensions, AsciiGifOutputOptions},
web::get_input_path,
timing::calculate_adjusted_frame_delays,
};
use rayon::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Handle both local files and URLs
let input_path = get_input_path("https://example.com/animation.gif").await?;
// Decode the GIF
let gif_data = decode_gif(&input_path)?;
// Configure the converter with custom character set
let custom_chars: Vec<char> = " ·∘○●◉".chars().collect();
let config = AsciiConverterConfig {
width: Some(80),
height: None,
char_aspect: 0.5,
invert: false,
detailed: true,
preserve_aspect_ratio: true,
scale_factor: Some(1.5), // 150% of original size
custom_charset: Some(custom_chars),
};
// Convert frames to ASCII in parallel
let results: Vec<(Vec<String>, u16)> = gif_data.frames
.par_iter()
.map(|frame| {
let ascii_frame = image_to_ascii(&frame.image, &config);
(ascii_frame, frame.delay_time_ms)
})
.collect();
let (ascii_frames, mut frame_delays): (Vec<_>, Vec<_>) = results.into_iter().unzip();
// Adjust frame delays for speed control (example: 2x speed)
frame_delays = calculate_adjusted_frame_delays(&frame_delays, Some(2.0), None)?;
// Display the animation
display_ascii_animation(&ascii_frames, &frame_delays, gif_data.loop_count, true).await?;
// Or save as ASCII GIF with speed control
let options = AsciiGifOutputOptions {
font_size: 14.0,
bg_color: image::Rgb([0, 0, 0]),
text_color: image::Rgb([255, 255, 255]),
..Default::default()
};
ascii_frames_to_gif_with_dimensions(
&ascii_frames,
&frame_delays,
gif_data.loop_count,
"output.gif",
&options,
Some((800, 600))
)?;
Ok(())
}
Monochora includes comprehensive logging for debugging and monitoring:
# Debug mode for troubleshooting with speed control
monochora -i problematic.gif --log-level debug --speed 1.5
# Trace mode for detailed analysis including timing calculations
monochora -i animation.gif --log-level trace --threads 4 --fps 45
# Error-only mode for production with speed control
monochora -i input.gif --log-level error --quiet --speed 2.0
Monochora works by:
gif crate with parallel processingThe ASCII conversion process maps pixel brightness to appropriate ASCII characters using either built-in character sets (simple or detailed) or custom user-defined sets. For colored output, it includes ANSI color codes for terminal display or renders characters with their original colors into a new GIF using advanced quantization techniques.
The speed control system handles frame timing adjustments:
Dithering enhances ASCII art quality by distributing quantization errors:
The ASCII GIF output uses several optimization techniques:
gif - For GIF decoding and encodingimage - For image manipulationimageproc - For drawing text on imagesrusttype - For font rendering in GIF outputclap - For command-line argument parsingcrossterm - For terminal manipulation and event handlinganyhow - For comprehensive error handlingtokio - For asynchronous operations and URL handlingreqwest - For HTTP downloads with timeout supporturl - For URL parsing and validationtempfile - For secure temporary file managementrayon - For high-performance parallel processingtracing - For structured logging and debuggingtracing-subscriber - For log formatting and filteringThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.