use std::path::Path;
use ab_glyph::{Font, PxScale};
use image::{Rgb, RgbImage};
use image_colored_text::draw::coord::DrawCoord;
use image_colored_text::text::paragraph::ColoredTextParagraph;
use image_colored_text::draw::multi_line::draw_multiline_colored_text;
use imageproc::drawing::draw_filled_rect_mut;
use imageproc::rect::Rect;
pub fn new_image_with_colored_text(path : &Path,
paragraph : &ColoredTextParagraph,
font: &impl Font,
scale: impl Into<PxScale> + Copy) {
let (width,height,_)= paragraph.paragraph_size(scale,font);
let margin = 10.0;
let img_width : f32 = 2.0*margin + width;
let img_height : f32 = 2.0*margin + height;
let mut image = RgbImage::new(
img_width as u32,
img_height as u32
);
draw_filled_rect_mut(&mut image,
Rect::at(0,0).of_size(img_width as u32,img_height as u32),
Rgb([255u8, 255u8, 255u8]));
draw_multiline_colored_text(&mut image,
&DrawCoord::StartingAt(margin),
&DrawCoord::StartingAt(margin),
paragraph,
font,
scale);
image.save(path).unwrap();
}