Closed backspaces closed 1 year ago
It is like the standard Image
object in the web - you must wait for onload or onerror to fire. Or just use await Image.load(url)
.
Javascript does not have a Image.load as far as I know. This is the promise-ified way to get an image in the browser:
new Promise((resolve, reject) => {
const img = new Image()
img.crossOrigin = 'Anonymous'
img.onload = () => resolve(img)
img.onerror = () => reject(`Could not load image ${url}`)
img.src = url
})
Would this work with skia?
Yep JS does not, it's merely a convenience method in skia canvas. That code should work fine with skia canvas as well.
Worked! Now both the browser and deno can use the same method for fetching files.
When getting an image using
The img is initially: Image { pending, src: undefined } .. but after a pause it is fulfilled: Image { width: 256, height: 256 }
Here's a file, skiaimg, showing this. You can also simply start a repl (deno repl -A --unstable) and drop all the text in it.
skiaimg: