Monochora
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.
Features
- High-performance parallel processing - Multi-threaded conversion for faster processing
- Convert animated GIFs to ASCII art animations
- Support for both local files and URLs - Download GIFs directly from the web
- Play the animations directly in your terminal
- Speed control - Adjust animation speed with multipliers or target FPS
- Save animations as text files or high-quality ASCII GIF files
- Support for colored ASCII art (with ANSI color codes)
- Customizable character sets - Built-in sets, inline strings, or custom files
- Multiple output options (terminal, text file, or GIF output)
- Advanced GIF output features:
- Adaptive color palettes for better quality
- Font size optimization for different scales
- Precision quantization for small fonts
- Custom background and text colors
- Preserve original GIF dimensions and aspect ratios
- Flexible scaling and dimension control
- Intelligent dimension calculation - Proper aspect ratio preservation and character scaling
- Quiet mode for batch processing
- Comprehensive error handling and validation
- Configurable logging levels for debugging and monitoring
Installation
Using Cargo (Recommended)
The easiest way to install Monochora is using Cargo:
From Source
-
Make sure you have Rust and Cargo installed. If not, install it from rust-lang.org.
-
Clone the repository:
-
Build and install:
Or just build without installing:
-
If you chose to just build, the binary will be available at
target/release/monochora
Usage
# Basic usage with local file (plays in terminal)
# Basic usage with URL - downloads and converts automatically
# Control animation speed - play at half speed
# Control animation speed - play at double speed
# Set target frames per second
# Save as ASCII text file
# Save to specific output file
# Generate colored ASCII in terminal
# Download from URL and generate colored ASCII with speed control
# Invert brightness
# Use simple character set
# Use custom character set (inline)
# Use custom character set from file
# List available character sets
# Save as high-quality ASCII GIF animation with speed adjustment
# Generate GIF with default name and target FPS
# Custom width (height calculated automatically to preserve aspect ratio)
# Custom width and height
# Scale the original dimensions (0.5 = half size, 2.0 = double size)
# Fit to terminal width
# Disable aspect ratio preservation
# White text on black background for GIF output with slow motion
# Black text on white background for GIF output
# Custom font size for GIF output (optimized palettes)
# High-performance processing with custom thread count and speed control
# Quiet mode for batch processing
# Debug with detailed logging
# Download from URL and save as high-quality ASCII GIF with speed control
Options
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
-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
Speed Control
Monochora provides flexible animation speed control through two mutually exclusive options:
Speed Multiplier (--speed)
Control animation playback speed with a multiplier:
- Values: 0.1 to 10.0
- Default: 1.0 (original speed)
- Examples:
--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
Target FPS (--fps)
Set a specific target frame rate:
- Values: 1 to 120 FPS
- Behavior: Adjusts frame delays to achieve the target frame rate
- Examples:
--fps 30- Standard video frame rate--fps 60- Smooth high frame rate--fps 12- Cinematic slow motion effect--fps 120- Ultra-smooth playback
Speed Control Examples
# Slow motion for detailed viewing
# Speed up a slow GIF
# Set consistent 24 FPS for cinematic feel
# Ultra-smooth 60 FPS terminal playback
# Very slow analysis mode
# Fast preview mode
# Combine with other features for optimal viewing
Character Sets
Monochora offers flexible character set options for different artistic styles and use cases:
Built-in Character Sets
- Simple (
--simple):.:-=+*#%@- Basic 10-character set for clean, fast conversion - Detailed (default): Full 70-character set with fine gradations for high-quality output
Custom Character Sets
Create your own character palettes for specialized needs:
# Artistic styles
# Cultural/linguistic
# Specialized applications
Character Set Files
Store reusable character sets in text files:
# Create a character set file
# Organize sets by category
Character Set Rules
- Order: Characters must be ordered from darkest to lightest
- Length: Minimum 2 characters, maximum 256 characters
- Uniqueness: All characters must be unique
- Content: No control characters (except tab/newline in files)
- Unicode: Full UTF-8 support for international characters
Listing Available Sets
Use --list-charsets to see examples and usage:
Important Notes
Output Mode Restrictions
Monochora enforces exclusive output modes to avoid conflicts:
- Terminal display: Default mode when no output options are specified
- Text file output: Use
--saveor--output <file> - GIF output: Use
--gif-output [path]
You cannot combine multiple output modes in a single command.
Character Set Restrictions
Character set options are mutually exclusive:
- Built-in sets:
--simple(default uses detailed set) - Inline custom:
--charset "characters" - File-based custom:
--charset-file path.txt
You cannot combine multiple character set options in a single command.
Speed Control Restrictions
Speed control options are mutually exclusive:
- Speed multiplier:
--speed <multiplier>(0.1-10.0) - Target FPS:
--fps <frame_rate>(1-120)
You cannot use both --speed and --fps in the same command.
Background Color Options
--white-on-blackand--black-on-whitecan only be used with--gif-output- These options are mutually exclusive
- Without these flags, GIF output uses default colors (white text on black background)
Terminal Fitting
--fit-terminalonly works with terminal display mode- Cannot be used with file output options (
--save,--output,--gif-output)
Font Size
--font-sizeonly applies to GIF output mode- Valid range: 0.1 to 100.0
- Default: 14.0 for optimal quality/performance balance
Performance Features
Monochora is optimized for high-performance processing:
- Parallel frame processing using Rayon for multi-core utilization
- Configurable thread pools - Set custom thread counts for your hardware
- Optimized memory usage - Efficient handling of large GIF files
- Adaptive algorithms - Different processing strategies based on font size and output type
- Smart frame timing - Efficient speed adjustment calculations
- Progress tracking - Real-time feedback on conversion progress (unless in quiet mode)
- Comprehensive validation - Input validation to prevent runtime errors
Performance Examples
# Use all CPU cores for maximum speed with fast playback
# Quiet batch processing with speed control
# High-performance colored terminal output with smooth 60 FPS
# Debug mode with detailed logging and slow motion
Advanced GIF Output
The ASCII GIF output feature includes several advanced optimizations:
Adaptive Color Palettes
- Dynamic palette generation based on font size and colors
- Precision-optimized quantization for better text rendering
- Font-size aware color steps - More colors for smaller fonts, fewer for larger
- Smart color variations for enhanced text clarity
Quality Settings by Font Size
- Small fonts (< 2.0): 32 color steps with precision quantization
- Medium fonts (2.0-6.0): 16 color steps with balanced quality
- Large fonts (> 6.0): 8 color steps for optimal performance
Speed Control in GIF Output
- Frame timing preservation - Speed adjustments maintain smooth playback
- Optimized delay calculations - Ensures proper timing across different speeds
- Quality maintenance - Speed changes don't affect visual quality
Examples
# High-quality small text with slow motion (more colors, precision quantization)
# Optimized medium text with standard cinema FPS (balanced quality/performance)
# Fast large text with accelerated playback (fewer colors, optimized for speed)
# Custom styling with adaptive palettes and speed control
# Auto-generated output filename with speed adjustment
Examples
Terminal Animation
To play an animation in your terminal:
Press q or Esc to exit the animation.
Speed Control Examples
Control animation playback speed for different viewing experiences:
# Slow motion for detailed analysis
# Speed up slow animations
# Set consistent frame rate for smooth playback
# Ultra-smooth high frame rate display
# Cinematic 24 FPS with custom styling
Custom Character Set Examples
Explore different artistic styles with custom character sets:
# Minimalist density gradient with speed control
# Geometric progression with smooth FPS
# Technical documentation style with slow playback
# High-contrast for readability with fast preview
# Artistic braille output with controlled timing
URL Input Examples
Download and play a GIF from the internet:
# Simple terminal playback with speed control
# Colored ASCII with custom dimensions, character set, and FPS
# Download and save as high-quality ASCII GIF with speed adjustment
Colored Terminal Animation
# Standard colored output
# Colored output with speed control
Scale Animation
Scale the animation to half size while preserving aspect ratio:
# Basic scaling
# Scaling with speed control
Fit to Terminal
Make the animation fit your terminal width:
# Basic terminal fitting
# Terminal fitting with speed control
Custom Dimensions with Proper Character Scaling
The dimension system now properly accounts for character aspect ratios:
# Width-based scaling (height calculated for proper proportions)
# Height-based scaling (width calculated for proper proportions)
# Exact dimensions with speed control (may distort aspect ratio)
Save as ASCII Text
# Save with default filename
# Save to specific file with speed adjustment (affects timing comments if included)
# Save with custom character set and FPS control
Save as High-Quality ASCII GIF
# Default output filename (ascii_animation.gif) with speed control
# Custom output filename with character set and FPS
Custom Style GIF with Optimization
# High-quality output with custom styling, character set, and speed control
# Performance-optimized batch processing with FPS control
Large High-Quality ASCII GIF
Create a large, detailed ASCII GIF with optimized processing:
# Large scale with speed control
# High quality with smooth FPS
Error Handling and Validation
Monochora includes comprehensive input validation:
Dimension Validation
- Width and height must be between 1 and 10,000 characters
- Font size must be between 0.1 and 100.0
- Scale factor must be between 0.1 and 10.0
- Thread count must be between 1 and 1,000
Speed Control Validation
- Speed multiplier must be between 0.1 and 10.0
- Target FPS must be between 1 and 120
- Speed and FPS options are mutually exclusive
Character Set Validation
- Minimum 2 characters, maximum 256 characters
- All characters must be unique
- No control characters (except tab/newline in files)
- Proper UTF-8 encoding for Unicode characters
Conflict Detection
- Prevents combining incompatible output modes
- Validates color scheme combinations
- Ensures options are used with appropriate output types
- Prevents conflicting character set options
- Prevents conflicting speed control options
Common Error Messages
- Invalid font size: Font size out of valid range
- Invalid dimensions: Width or height out of bounds
- Invalid speed: Speed multiplier out of valid range (0.1-10.0)
- Invalid FPS: Target FPS out of valid range (1-120)
- Speed conflict: Cannot use both --speed and --fps options
- Invalid character set: Character set validation failed
- Config error: Conflicting or invalid option combinations
- Thread pool error: Issues with parallel processing setup
URL Support
Monochora supports downloading GIFs directly from URLs:
- Supported protocols: HTTP and HTTPS
- Automatic download: Files are downloaded to temporary storage and cleaned up automatically
- Content validation: Warns if the URL doesn't serve image content
- Timeout handling: 30-second timeout for downloads
- Progress indication: Shows download progress and file size
- Custom User-Agent: Identifies as monochora-gif-converter
URL Examples
# Download and convert a GIF from Giphy with speed control
# Download from any image hosting service with FPS control
# Works with direct links to GIF files with speed adjustment
Dimension Control & Character Scaling
Monochora offers intelligent dimension control with proper character aspect ratio handling:
- Default: Uses original GIF dimensions with character aspect correction
- Character aspect ratio: Automatically accounts for the ~2:1 width-to-height ratio of monospace characters
- --width only: Sets width, calculates height to preserve image aspect ratio
- --height only: Sets height, calculates width to preserve image aspect ratio
- --width and --height: Uses exact dimensions (may distort unless aspect preservation is disabled)
- --scale: Multiplies original dimensions by scale factor with character correction
- --fit-terminal: Fits to terminal width (when not saving to file)
- --preserve-aspect false: Disables automatic aspect ratio preservation
Dimension Examples
# Preserve image proportions with character scaling and speed control
# Scale with proper character proportions and FPS control
# For GIF output, dimensions are calculated for target pixel size with speed adjustment
Library Usage
Monochora can also be used as a library in your Rust projects:
use ;
use *;
async
Debugging and Logging
Monochora includes comprehensive logging for debugging and monitoring:
Log Levels
- error: Only critical errors
- warn: Warnings and errors
- info: General information, warnings, and errors (default)
- debug: Detailed processing information including speed adjustments
- trace: Extremely verbose output for debugging
Debugging Examples
# Debug mode for troubleshooting with speed control
# Trace mode for detailed analysis including timing calculations
# Error-only mode for production with speed control
How It Works
Monochora works by:
- Input validation: Comprehensive validation of all command-line arguments including speed parameters
- Input handling: Accepts both local file paths and URLs (HTTP/HTTPS)
- URL processing: Downloads GIFs from URLs to temporary files when needed
- GIF decoding: Decodes GIF frames using the
gifcrate with parallel processing - Character set selection: Chooses appropriate character set (built-in, custom inline, or file-based)
- ASCII conversion: Converts each frame to ASCII art based on pixel brightness using parallel processing
- Dimension calculation: Intelligently calculates dimensions with proper character aspect ratio handling
- Speed adjustment: Calculates adjusted frame delays based on speed multiplier or target FPS
- Advanced output generation:
- Terminal display and GIF output with color support and speed control
- Text file output with frame separators
- High-quality ASCII GIF generation with adaptive palettes and timing preservation
The 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.
Speed Control Processing
The speed control system handles frame timing adjustments:
- Speed multiplier mode: Multiplies original frame delays by the inverse of the speed factor
- Target FPS mode: Calculates uniform frame delays to achieve the specified frame rate
- Validation: Ensures resulting delays are within reasonable bounds (10ms minimum)
- Conflict resolution: Prevents simultaneous use of both speed control methods
- Timing preservation: Maintains smooth playback across different output formats
Advanced GIF Generation Process
The ASCII GIF output uses several optimization techniques:
- Adaptive palette creation based on font size and color scheme
- Precision quantization with different algorithms for different font sizes
- Smart color distance calculation optimized for text rendering
- Frame-by-frame parallel rendering for improved performance
- Embedded font rendering using DejaVu Sans Mono for consistent output
- Speed-aware timing that preserves smooth playback at different speeds
Performance Characteristics
- Multi-threaded processing: Utilizes all available CPU cores by default
- Memory efficient: Streams processing to handle large GIF files
- Scalable: Performance improves with more CPU cores
- Optimized algorithms: Different processing strategies based on output type and quality settings
- Efficient speed calculations: Minimal overhead for frame timing adjustments
Typical Performance
- Small GIFs (< 1MB): Near-instantaneous processing with speed control
- Medium GIFs (1-10MB): 1-5 seconds on modern hardware, timing adjustments add <1% overhead
- Large GIFs (10MB+): Scales linearly with thread count, speed control remains efficient
- Batch processing: Quiet mode minimizes I/O overhead, speed adjustments are computed once
Dependencies
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 filtering
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.