somnid
somnid
DDeno
Created by somnid on 10/14/2024 in #help
Can Deno Jupyter output images like jpegs?
Thanks
8 replies
DDeno
Created by somnid on 10/14/2024 in #help
Can Deno Jupyter output images like jpegs?
//works
import { encodeBase64 } from "jsr:@std/encoding";

const img = encodeBase64(await Deno.readFile("./my-image.jpg"));

await Deno.jupyter.display({
"image/jpeg" : img
}, { raw: true })
//works
import { encodeBase64 } from "jsr:@std/encoding";

const img = encodeBase64(await Deno.readFile("./my-image.jpg"));

await Deno.jupyter.display({
"image/jpeg" : img
}, { raw: true })
8 replies
DDeno
Created by somnid on 10/14/2024 in #help
Can Deno Jupyter output images like jpegs?
Ah it's just the plain base64 string, no data url.
8 replies
DDeno
Created by somnid on 10/14/2024 in #help
Can Deno Jupyter output images like jpegs?
import { encodeBase64 } from "jsr:@std/encoding";

export function arrayBufferToUrl(arrayBuffer: ArrayBuffer){
return `data:image/jpeg;base64,${encodeBase64(arrayBuffer)}`;
}

const img = await Deno.readFile("./my-image.jpg");
const url = arrayBufferToUrl(img);

await Deno.jupyter.display({
"image/jpeg" : url
}, { raw: true })
import { encodeBase64 } from "jsr:@std/encoding";

export function arrayBufferToUrl(arrayBuffer: ArrayBuffer){
return `data:image/jpeg;base64,${encodeBase64(arrayBuffer)}`;
}

const img = await Deno.readFile("./my-image.jpg");
const url = arrayBufferToUrl(img);

await Deno.jupyter.display({
"image/jpeg" : url
}, { raw: true })
Seems closer. I get a broken image icon with this. url works if I paste in the browser.
8 replies