From 0ef2d2acd900dc59f27d25dc2440a1309940def2 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sun, 8 Nov 2020 15:31:57 +0000 Subject: [PATCH] return image size so the client side can determine whether to crop or not --- script.js | 10 +++++++++- src/lib.rs | 9 +++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index 82b036d..f7d74e5 100644 --- a/script.js +++ b/script.js @@ -165,7 +165,15 @@ async function run() { buttonImageProceed.removeAttribute("disabled"); } - cropper.loadImage(e.target.result); + if (load_image(e.target.result) === "128×128") { + // we can't just do `buttonImageProceed.click()` + // because this calls the handleImage() function, which we don't want here + el("page-image").style.display = "none"; + el("page-room").style.display = "block"; + loadPreview(); + } else { + cropper.loadImage(e.target.result); + } }, "image"); }); diff --git a/src/lib.rs b/src/lib.rs index 390b07b..4d133b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -101,22 +101,23 @@ pub fn load_image(image_base64: String) -> String { Ok(image) => { match image::load_from_memory(image.as_ref()) { Ok(image) => { + let size = format!("{}×{}", image.width(), image.height()); // todo get rid of magic numbers! what about Bitsy HD? let image = image.resize(128, 128, CatmullRom); state.image = Some(image); - "OK" + size }, _ => { state.image = None; - "Couldn't load image" + "Couldn't load image".to_string() } } }, _ => { state.image = None; - "Couldn't decode image" + "Couldn't decode image".to_string() } - }.to_string() + } } #[wasm_bindgen]