Crate image_ascii
source ·Expand description
A library to transform images into ASCII art. Both into text and new images consisting of letters.
Examples
Generating text with default parameters
use image::{io::Reader as ImageReader};
use image_ascii::TextGenerator;
let image = ImageReader::open("tests/data/images/diamond_sword.png")
.unwrap()
.decode()
.unwrap();
let result: String = TextGenerator::new(&image).generate();
Generating text with custom parameters
use image::{io::Reader as ImageReader};
use image_ascii::TextGenerator;
let image = ImageReader::open("tests/data/images/diamond_sword.png")
.unwrap()
.decode()
.unwrap();
let result: String = TextGenerator::new(&image)
.set_include_alpha(false)
.set_density_chars(&['.', '/', '%', '#'])
.unwrap()
.generate();
Generating an image with default parameters
use image::{io::Reader as ImageReader, RgbaImage};
use rusttype::Font;
use image_ascii::ImageGenerator;
let image = ImageReader::open("tests/data/images/diamond_sword.png")
.unwrap()
.decode()
.unwrap();
let bytes = std::fs::read("src/fonts/Ubuntu-Regular.ttf").unwrap();
let font = Font::try_from_bytes(&bytes).unwrap();
let result: RgbaImage = ImageGenerator::new(&image, &font).generate();
Generating an image with custom parameters
use image::{io::Reader as ImageReader, RgbaImage, DynamicImage, Rgba};
use rusttype::Font;
use image_ascii::ImageGenerator;
let image = ImageReader::open("tests/data/images/diamond_sword.png")
.unwrap()
.decode()
.unwrap();
let bytes = std::fs::read("src/fonts/Ubuntu-Regular.ttf").unwrap();
let font = Font::try_from_bytes(&bytes).unwrap();
let background = DynamicImage::ImageRgba8(RgbaImage::from_fn(64, 64, |x, y| {
Rgba([x as u8, y as u8, x as u8, 255u8])
}));
let result: RgbaImage = ImageGenerator::new(&image, &font)
.set_scale_x(5)
.set_scale_y(5)
.set_text_color(image_ascii::ImageGeneratorTextColor::CopyFromImage)
.set_background(image_ascii::ImageGeneratorBackground::Image(&background))
.generate();
Structs
- Structure used to generate ASCII art images
- Structure used to generate ASCII art strings.
Enums
- Enumeration of background generation methods for ImageGenerator.
- Enumeration of possible text color for ImageGenerator.