Donaldcwl / browser-image-compression

Image compression in web browser
MIT License
1.3k stars 160 forks source link

Image size is expanding instead of compressing #167

Closed Omansh14 closed 2 years ago

Omansh14 commented 2 years ago

export const imageCompresser = (file) => { console.log(originalFile size ${file.size / 1024 / 1024} MB); if (file?.length > 0) { const imageFile = file[0]; const options = { maxSizeMB: 1, maxWidthorHeight: 300, maxIteration: 30, useWebWorker: true, }; imageCompression(imageFile, options) .then((compressedFile) => { console.log(compressedFile size ${compressedFile.size / 1024 / 1024} MB); return compressedFile; }); } if (file) { const imageFile = file; const options = { maxSizeMB: 1, maxWidthorHeight: 300, maxIteration: 30, useWebWorker: true, }; imageCompression(imageFile, options) .then((compressedFile) => { console.log(compressedFile size ${compressedFile.size / 1024 / 1024} MB); return compressedFile; }); } return file; };

I'm using this function another file to take 'file' and integrate it with backend. The console statements are showing that size is getting reduced. But the actual image which is getting transferred to backend is expanding in size.

Please suggest changes using which it runs properly. Thanks in Advance.