Skip to content

Commit

Permalink
getting crummy, weird, just grey with a line of color at the top
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimbbp committed Apr 10, 2024
1 parent f93e0fb commit 4ee906b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions spritefire/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ impl Crop {
) -> Result<DynamicImage, ImageError> {
//TODO this needs its own return type
let img = image::open(image_path)?;

//view xy is top left. This adjusts for that:
let crop_width = (img.width() - crop_boundaries.width) / 2;
let crop_height = (img.height() - crop_boundaries.height) / 2;

let subimage = img
.view(
crop_boundaries.x,
crop_boundaries.y,
crop_width,
crop_height,
crop_boundaries.width,
crop_boundaries.height,
)
Expand Down Expand Up @@ -102,18 +107,18 @@ pub fn build_sprites(input: &str, save: &str) -> std::io::Result<()> {
//TODO: Open image, pass to resize
let crop_boundaries = Crop::simple_prep(&image_path).unwrap();
let cropped_image = Crop::crop_image(&image_path, &crop_boundaries).unwrap();
save_image(cropped_image, save)
let _ = cropped_image.save(save);
let file_name = image_path.file_name().unwrap();
let mut save_path = PathBuf::from(save);
save_path.push(file_name);
let _ = cropped_image.save(save_path);
//error handle later
}
}
}
Ok(())
}

fn save_image(image: DynamicImage, path: &str) {
let _ = image.save(path);
}

//Advanced:
//fn alpha background
// detects background and replaces it with an alpha layer
Expand Down
2 changes: 1 addition & 1 deletion spritefire/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fs;
use spritefire::build_sprites;

fn main() {
let test_input = "/Users/joachimpfefferkorn/repos/spritefire/assets/sprites_512";
let test_input = "/Users/joachimpfefferkorn/Desktop/brasilia";
let test_output: &str = "/Users/joachimpfefferkorn/repos/spritefire/output";
let _ = build_sprites(&test_input, test_output);
//Ishan's web code
Expand Down

0 comments on commit 4ee906b

Please sign in to comment.