From d6261f647c38fee8e36f4a31f03e24dd34ea080b Mon Sep 17 00:00:00 2001 From: joachimbbp <104856283+joachimbbp@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:04:03 -0400 Subject: [PATCH] WIP --- spritefire/src/lib.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spritefire/src/lib.rs b/spritefire/src/lib.rs index 87720f8..19dd422 100644 --- a/spritefire/src/lib.rs +++ b/spritefire/src/lib.rs @@ -6,6 +6,39 @@ use std::path::{Path, PathBuf}; //fn simple_resize // resizes every image in a folder to proper spritefire resolution +//TODO: +//struct or func for background removal + +enum Aspect { + Horizontal, + Vertical, + Square, +} + +struct Crop { + aspect: Aspect, + x: u16, + y: u16, + width: u16, + height: u16, +} +impl Crop { + fn simple(image_path: &PathBuf) -> Self { + let img = image::open(image_path); + //Q: How to handle errors in this sort of thing? + } + fn get_aspect(image_path: &PathBuf) -> Aspect { + let (rx, ry) = img.dimensions(); + if rx > ry { + Aspect::Horizontal + } else if rx < ry { + Aspect::Horizontal + } else { + Aspect::Square + } + } +} + pub fn build_sprites(input: &str, save: &str) -> std::io::Result<()> { let input_folder = Path::new(input); if input_folder.is_dir() { @@ -41,6 +74,11 @@ fn simple_resize(image_path: &PathBuf, save: &str) -> Result<(), ImageError> { Ok(()) } +fn read_dimensions(image_path: &PathBuf) -> Result<(u32, u32), ImageError> { + let img = image::open(image_path)?; + Ok(img.dimensions()) +} + //Advanced: //fn alpha background // detects background and replaces it with an alpha layer