Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Last active October 9, 2021 16:45
Show Gist options
  • Save alextanhongpin/0f4ca5d0098a3410e0960b3ee2420bbb to your computer and use it in GitHub Desktop.
Save alextanhongpin/0f4ca5d0098a3410e0960b3ee2420bbb to your computer and use it in GitHub Desktop.
Sample usage for compress.js library.
const compress = new Compress()
const upload = document.getElementById('upload')
upload.addEventListener('change', (evt) => {
const files = [...evt.target.files]
compress.compress(files, {
size: 4, // the max size in MB, defaults to 2MB
quality: 0.75, // the quality of the image, max is 1,
maxWidth: 1920, // the max width of the output image, defaults to 1920px
maxHeight: 1920, // the max height of the output image, defaults to 1920px
resize: true, // defaults to true, set false if you do not want to resize the image width and height
rotate: true // Enables rotation, defaults to false
}).then((data) => {
// returns an array of compressed images
console.log(data)
})
}, false)
@sergiorighi
Copy link

sergiorighi commented Oct 27, 2017

I'm having the error "v.map is not a function".

@DineshKachhot
Copy link

DineshKachhot commented Jul 6, 2021

I am using compress.js in my react native project, I want to reduce file size of a file picked using react-native-camera,

const photo = await camera.current.takePictureAsync();

Using adding this photo as array in compress.js like this,

const files = [photo]; const compressedFiles = await compress.compress(files, { size: 4, quality: 0.75, maxWidth: 600, maxHeight: 600, resize: true, });

Getting following error while compress called,

TypeError: t.slice is not a function. (In 't.slice(0, 65536)', 't.slice' is undefined)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment