return image size so the client side can determine whether to crop or not
This commit is contained in:
parent
f9b0f6b6db
commit
0ef2d2acd9
10
script.js
10
script.js
|
@ -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");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue