Crates.io | image_ascii |
lib.rs | image_ascii |
version | 0.1.1 |
source | src |
created_at | 2023-08-29 22:55:45.246091 |
updated_at | 2023-08-29 23:21:40.063842 |
description | A library to transform images into ASCII art. Both into text and images consisting of letters. |
homepage | |
repository | |
max_upload_size | |
id | 958509 |
size | 9,534,309 |
A simple Rust crate for transforming images into ascii art.
This project on Crates.io
This project on Github
use image::{io::Reader as ImageReader, RgbaImage, DynamicImage, Rgba};
use rusttype::Font;
use image_ascii::ImageGenerator;
let image = ImageReader::open("tests/data/images/landscape.jpg")
.unwrap()
.decode()
.unwrap();
let bytes = std::fs::read("src/fonts/Ubuntu-Regular.ttf").unwrap();
let font = Font::try_from_bytes(&bytes).unwrap();
let res = ImageGenerator::new(&image, &font)
.set_scale_x(4)
.set_scale_y(4)
.set_text_color(image_ascii::ImageGeneratorTextColor::CopyFromImage)
.generate();
let res = image::imageops::resize(
&res,
image.width(),
image.height(),
image::imageops::FilterType::CatmullRom,
);
res.save("landscape.png").unwrap();