chickensources/
subbody.rs

1use image::{DynamicImage, Rgba};
2use imageproc::drawing;
3use once_cell::sync::Lazy;
4use rusttype::Font;
5
6use crate::utils;
7
8static FONT: Lazy<Font<'static>> = Lazy::new(|| {
9    let font_data = include_bytes!("fonts/PublicSans-BoldItalic.ttf");
10    let font = Font::try_from_bytes(font_data).expect("font should load");
11
12    font
13});
14
15const COLOR: Rgba<u8> = Rgba([255, 255, 255, 255]);
16
17pub fn draw(img: &mut DynamicImage, subbody: &str) {
18    let side_length = img.height();
19
20    let max_w = 5 * side_length / 6;
21    let max_h = side_length / 50;
22
23    let (scale, text_w, _) = utils::text_size(&FONT, max_w, max_h, subbody);
24
25    let text_x = (side_length - text_w) / 2;
26    let text_y = 9 * side_length / 10;
27
28    drawing::draw_text_mut(
29        img,
30        COLOR,
31        text_x.try_into().unwrap(),
32        text_y.try_into().unwrap(),
33        scale,
34        &FONT,
35        subbody,
36    );
37}