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]