| Crates.io | libasciic |
| lib.rs | libasciic |
| version | 1.1.1 |
| created_at | 2025-11-19 02:26:51.687466+00 |
| updated_at | 2025-11-30 03:11:26.665387+00 |
| description | A library for converting images to ASCII art with optional ANSI colorization |
| homepage | https://github.com/S0raWasTaken/bad_apple |
| repository | https://github.com/S0raWasTaken/bad_apple |
| max_upload_size | |
| id | 1939335 |
| size | 52,268 |
A Rust library for converting images to ASCII art with optional ANSI colorization.
image crateAdd this to your Cargo.toml:
[dependencies]
libasciic = "1.1.0"
use std::fs::File;
use libasciic::{AsciiBuilder, Style};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("image.png")?;
let ascii = AsciiBuilder::new(file)
.dimensions(80, 40)
.colorize(true)
.style(Style::FgPaint)
.make_ascii()?;
println!("{}", ascii);
Ok(())
}
use std::fs::File;
use libasciic::AsciiBuilder;
let file = File::open("photo.jpg")?;
let ascii = AsciiBuilder::new(file)
.dimensions(100, 50)
.make_ascii()?;
println!("{}", ascii);
use std::fs::File;
use libasciic::{AsciiBuilder, Style};
let file = File::open("image.png")?;
let ascii = AsciiBuilder::new(file)
.dimensions(120, 60)
.colorize(true)
.style(Style::BgPaint)
.charset(".:;+=xX$@")
.threshold(10) // Reduce output size
.make_ascii()?;
print!("{}", ascii);
use std::fs::File;
use libasciic::{AsciiBuilder, Style};
let file = File::open("artwork.png")?;
let ascii = AsciiBuilder::new(file)
.dimensions(80, 40)
.colorize(true)
.style(Style::BgOnly)
.make_ascii()?;
print!("{}", ascii);
use std::fs::File;
use libasciic::{AsciiBuilder, FilterType};
let file = File::open("photo.jpg")?;
let ascii = AsciiBuilder::new(file)
.dimensions(150, 75)
.filter_type(FilterType::Lanczos3)
.colorize(true)
.make_ascii()?;
print!("{}", ascii);
AsciiBuilderThe main builder struct for creating ASCII art. All methods are chainable.
new(image: R) -> 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) -> 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 artStyle EnumControls 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 charactersThe 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(".'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$")
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 valueHigher values reduce output size but may decrease color accuracy. Recommended range: 5-20.
FilterType::Lanczos3 or FilterType::CatmullRom when downscalingthreshold()) to significantly reduce the size of colorized outputBgOnly style works well for creating color-accurate terminal imagesMIT
S0ra (S0raWasTaken)