Skip to content

Instantly share code, notes, and snippets.

@juanlatorre
Forked from schabluk/ract-dropzone-image.js
Last active April 30, 2021 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanlatorre/2b9804879aafffe5bad669272d00b676 to your computer and use it in GitHub Desktop.
Save juanlatorre/2b9804879aafffe5bad669272d00b676 to your computer and use it in GitHub Desktop.
React-Dropzone get image width, height and base64 data
const onDrop = useCallback((acceptedFiles) => {
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