Crates.io | text-image |
lib.rs | text-image |
version | 0.2.0 |
source | src |
created_at | 2023-11-28 06:09:32.808433 |
updated_at | 2024-09-21 15:26:02.025426 |
description | A proc-macro to generate raw image from text and a font file, for embedded-graphics. |
homepage | https://github.com/andelf/text-image |
repository | https://github.com/andelf/text-image |
max_upload_size | |
id | 1051631 |
size | 32,371 |
A Rust macro crate for converting text and images to various image formats, primarily for use with embedded graphics systems.
Add this to your Cargo.toml
:
[dependencies]
text-image = "0.1.0"
Convert text to a grayscale image:
use text_image::text_image;
use embedded_graphics::{image::ImageRaw, pixelcolor::Gray8};
fn main() {
let (w, h, raw) = text_image!(
text = "Hello, world!哈哈这样也行",
font = "LXGWWenKaiScreen.ttf",
font_size = 48.0,
inverse,
Gray4,
);
let raw_image = ImageRaw::<Gray8>::new(raw, w);
}
Convert a color image to a 1-bit monochrome image:
use text_image::monochrome_image;
let (w, h, img_raw) = monochrome_image!("path/to/image.png", channel = 1);
Convert a color image to a 2-bit 4-color image:
use text_image::quadcolor_image;
let (w, h, img_raw) = quadcolor_image!("path/to/image.png");
Convert an image to grayscale with specified bit depth:
use text_image::gray_image;
let (w, h, img_raw) = gray_image!("path/to/image.png", Gray4);
text
: The text to convert (required for text_image!
)font
: Path to the font file (required for text_image!
)font_size
: Font size in pixels (default: 16.0)inverse
: Invert the colors (optional)line_spacing
: Additional space between lines (optional)Gray2
, Gray4
, Gray8
: Specify the bit depth for grayscale outputContributions are welcome! Please feel free to submit a Pull Request.