Skip to content

Instantly share code, notes, and snippets.

@getadeo
Forked from schabluk/ract-dropzone-image.js
Created June 29, 2023 15:26
Show Gist options
  • Save getadeo/097488c9da032ece96abbd50dacd5742 to your computer and use it in GitHub Desktop.
Save getadeo/097488c9da032ece96abbd50dacd5742 to your computer and use it in GitHub Desktop.
React-Dropzone get image width, height and base64 data
onDrop = (acceptedFiles, rejectedFiles) => {
const file = acceptedFiles.find(f => f)
const i = new Image()
i.onload = () => {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = () => {
console.log({
src: file.preview,
width: i.width,
height: i.height,
data: reader.result
})
}
}
i.src = file.preview
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment