Created
February 13, 2022 15:31
-
-
Save VehpuS/79842ebb924e9f5257d49e53412cf947 to your computer and use it in GitHub Desktop.
Awaitable loaded image object - useful for drawing to canvas, getting dimensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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