Skip to content

Instantly share code, notes, and snippets.

@VehpuS
Created February 13, 2022 15:31
Show Gist options
  • Save VehpuS/79842ebb924e9f5257d49e53412cf947 to your computer and use it in GitHub Desktop.
Save VehpuS/79842ebb924e9f5257d49e53412cf947 to your computer and use it in GitHub Desktop.
Awaitable loaded image object - useful for drawing to canvas, getting dimensions
const getLoadedImg = (url: string) => new Promise<HTMLImageElement>(resolve => {
const img = new Image();
img.crossOrigin = "anonymous";
img.src = url
img.onload = function () {
resolve(img);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment