Last active
January 27, 2020 23:41
-
-
Save crrmacarse/64d224243a8fec02346308ec08ee4886 to your computer and use it in GitHub Desktop.
Image Compressor
This file contains 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
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