return image size so the client side can determine whether to crop or not

This commit is contained in:
Max Bradbury 2020-11-08 15:31:57 +00:00
parent f9b0f6b6db
commit 0ef2d2acd9
2 changed files with 14 additions and 5 deletions

View File

@ -165,7 +165,15 @@ async function run() {
buttonImageProceed.removeAttribute("disabled"); 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"); }, "image");
}); });

View File

@ -101,22 +101,23 @@ pub fn load_image(image_base64: String) -> String {
Ok(image) => { Ok(image) => {
match image::load_from_memory(image.as_ref()) { match image::load_from_memory(image.as_ref()) {
Ok(image) => { Ok(image) => {
let size = format!("{}×{}", image.width(), image.height());
// todo get rid of magic numbers! what about Bitsy HD? // todo get rid of magic numbers! what about Bitsy HD?
let image = image.resize(128, 128, CatmullRom); let image = image.resize(128, 128, CatmullRom);
state.image = Some(image); state.image = Some(image);
"OK" size
}, },
_ => { _ => {
state.image = None; state.image = None;
"Couldn't load image" "Couldn't load image".to_string()
} }
} }
}, },
_ => { _ => {
state.image = None; state.image = None;
"Couldn't decode image" "Couldn't decode image".to_string()
} }
}.to_string() }
} }
#[wasm_bindgen] #[wasm_bindgen]