nitish24p / react-worker-image

React component to fetch image resources via web workers 🤖🤖
MIT License
232 stars 18 forks source link

Use the image.decode() api #9

Closed nitish24p closed 6 years ago

nitish24p commented 6 years ago

image.decode is part of the new spec, which decodes images and returns a promise, see if this can be incorporated into it. Also try to check for browser support. And have a silent fallback / failing mechanism

manjula-dube commented 6 years ago

Does it decode in bit array?

kurtextrem commented 6 years ago

Why did you guys close this? According to the spec: https://html.spec.whatwg.org/dev/embedded-content.html "Because the decode() method attempts to ensure that the decoded image data is available for at least one frame, it can be combined with the requestAnimationFrame() API. This means it can be used with coding styles or frameworks that ensure that all DOM modifications are batched together as animation frame callbacks"

which should mean, if we change https://github.com/nitish24p/react-worker-image/blob/master/lib/ImageWorker.js#L82 to

image.decode().then(this.onLoad)

it should work (of course we have to check for browser support and if the browser doesn't support it, we go with the onload method)