Skip to content

Instantly share code, notes, and snippets.

@crrmacarse
Last active January 27, 2020 23:41
Show Gist options
  • Save crrmacarse/64d224243a8fec02346308ec08ee4886 to your computer and use it in GitHub Desktop.
Save crrmacarse/64d224243a8fec02346308ec08ee4886 to your computer and use it in GitHub Desktop.
Image Compressor
import imageCompressor from 'browser-image-compression'
const blobToFile = async (blob, file) => {
const result = new File([blob], file.name, { type: file.type, lastModified: Date.now() });
return result
}
const compressImage = async (maxWidth, file) => {
const options = {
maxWidthOrHeight: maxWidth,
}
const image = await imageCompressor(file, options)
return blobToFile(image, file)
}
export default compressImage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment