Last active
October 9, 2021 16:45
-
-
Save alextanhongpin/0f4ca5d0098a3410e0960b3ee2420bbb to your computer and use it in GitHub Desktop.
Sample usage for compress.js library.
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
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) |
I'm having the error "v.map is not a function".
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
Hi, I'm using your code and I like to replace the input file content by the compress image but I don't know how
I was trying by using
But it doesn't work.