Created
February 7, 2022 22:18
-
-
Save materkel/df9ba660d360f74800bca06213fe7f3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function fetchFileDimensionsAsBlob(file: File) { | |
const src = URL.createObjectURL(file); | |
const image = new Image(); | |
image.onload = function() { | |
resolve({ | |
src, | |
dimensions: { | |
width: image.width, | |
height: image.height, | |
}, | |
}); | |
}; | |
image.src = src; | |
} | |
function fetchFileDimensionsAsBase64(file: File) { | |
return new Promise((resolve) => { | |
const fileReader = new FileReader(); | |
fileReader.onload = (fileEvent) => { | |
const src = fileEvent.target.result as string; | |
const image = new Image(); | |
image.onload = function() { | |
resolve({ | |
src, | |
dimensions: { | |
width: image.width, | |
height: image.height, | |
}, | |
}); | |
}; | |
image.src = src; | |
}; | |
fileReader.readAsDataURL(file); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment