extern crate image;
extern crate rusttype;
use image::{DynamicImage, Rgba};
use rusttype::{point, Font, Scale};
fn main() {
let font_data = include_bytes!("../fonts/wqy-microhei/WenQuanYiMicroHei.ttf");
let font =
Font::from_bytes(font_data as &[u8]).expect("Error constructing Font");
let mut image = DynamicImage::new_rgba8(500, 100).to_rgba();
let size = 32.0;
let scale = Scale { x: size, y: size };
let text = "This is RustType rendered into a png!";
let colour = (150, 0, 0);
let start = point(20.0, 50.0);
for glyph in font.layout(text, scale, start) {
if let Some(bounding_box) = glyph.pixel_bounding_box() {
glyph.draw(|x, y, v| {
image.put_pixel(
x + bounding_box.min.x as u32,
y + bounding_box.min.y as u32,
Rgba {
data: [colour.0, colour.1, colour.2, (v * 255.0) as u8],
},
)
});
}
}
image.save("image_example.png").unwrap();
println!("Generated: image_example.png");
}