Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
file.type.slice(6, 9) === 'gif'
? file
: await browserImageCompression(file, 0.3)
// Sometimes compression can increase its size
compressedFile = file.size < compressedFile.size ? file : compressedFile
// It's still too big
if (compressedFile.size > 3e6)
return this.setState({
imageFileDataURL: null,
imageFileInfoMessage:
'Image is too big and cannot be resized. It must be less than 100KB.'
})
// It's small enough now, check dimensions
const imageFileDataURL = await browserImageCompression.getDataUrlFromFile(
compressedFile
)
const img = await browserImageCompression.loadImage(imageFileDataURL)
if (img.width < 250 || img.height < 250)
return this.setState({
imageFileDataURL: null,
imageFileInfoMessage:
'Image is too small. It must be more than 250px wide and 250px tall.'
})
// All good
this.setState({
imageFileDataURL,
imageFileInfoMessage: null
})
}