service : {
"fractal": (nat32, nat32) -> (blob) query;
}
// An example of generating julia fractals.
// https://crates.io/crates/image
use std::io::Cursor;
#[ic_cdk::query]
fn fractal(imgx:u32, imgy:u32) -> Vec<u8> {
︙
let mut result = vec![];
imgbuf.write_to(&mut Cursor::new(&mut result), image::ImageOutputFormat::Png).unwrap();
result
}
// Converts the given blob into a data url such that it can be assigned as a
// target of a link of as an image source.
function convertToDataUrl(blob) {
return new Promise((resolve, _) => {
const fileReader = new FileReader();
fileReader.readAsDataURL(blob);
fileReader.onloadend = function () {
resolve(fileReader.result);
}
});
}