Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Promise to wait for an image to have loaded #63

Open
severo opened this issue Feb 11, 2020 · 1 comment
Open

Promise to wait for an image to have loaded #63

severo opened this issue Feb 11, 2020 · 1 comment

Comments

@severo
Copy link
Collaborator

severo commented Feb 11, 2020

We could use https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode#Examples instead of

export async function fetchImage ({
...

@severo
Copy link
Collaborator Author

severo commented Feb 11, 2020

fetchImage = src => {
  const img = new Image();
  img.src = src;
  return img
    .decode()
    .then(() => img)
    .catch(encodingError => {
      // Do something with the error.
      throw new Error(`Image ${src} could not be loaded: ${encodingError}`);
    });
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant