Last active
August 7, 2018 01:53
-
-
Save brunossn/60febeabb622fc0bc33d0f6a270d4c60 to your computer and use it in GitHub Desktop.
A async function in TypeScript to convert an url to a HTMLImageElement
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
// Example: | |
// const catImage = await ImageFromUrl('./img/cat.png'); | |
async function ImageFromUrl(urlImage: string): Promise<HTMLImageElement> { | |
return new Promise<HTMLImageElement>(resolve => { | |
let base = new Image(); | |
base.src = urlImage; | |
base.onload = function() { | |
resolve(base); | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment