function imageSize (image) {
return new Promise((resolve, reject) => {
try {
const fileReader = new FileReader()
fileReader.onload = () => {
const img = new Image()
img.onload = () => {
resolve({ width: img.width, height: img.height })
}
img.src = fileReader.result
}
fileReader.readAsDataURL(image)
} catch (e) {
reject(e)
}
})
}
Created
June 6, 2020 16:48
-
-
Save zmts/3388e16fe6b2983a541e91c40fcc2eb3 to your computer and use it in GitHub Desktop.
Get image width and height with JavaScript
Thanks a lot!
I always receive that image is undefined when I add readAsDataUrl
Works not in chrome with
`
<svg width="100%" height="100%" viewBox="0 0 4963 3509" ...`
SVGs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please put this example in context(in an html page). showing <input..multiple..image only etc. that would be very helpful, thank you