use rimage::image::{imageops::FilterType, DynamicImage, GenericImageView};
use std::fs;
use std::path::Path;
pub(crate) fn resize_by_width(image: DynamicImage, width: u32) -> anyhow::Result<DynamicImage> {
let (w, h) = image.dimensions();
if width >= w {
return Ok(image);
}
let scale = (width as f64) / (w as f64);
let new_w = width;
let new_h = ((h as f64) * scale) as u32;
let img_out = image.resize(new_w, new_h, FilterType::Lanczos3);
Ok(img_out)
}
pub(crate) fn create_directory_if_not_exists(path: &str) -> anyhow::Result<()> {
let path = Path::new(path);
if !path.exists() {
fs::create_dir_all(path)?;
}
Ok(())
}