In this example I am using the filetype option as .png
but its not working as expected.
import imageCompression from 'browser-image-compression';
const compressImage = async (pic) => {
const options = {
maxSizeMB: 1,
maxWidthOrHeight: 1024,
useWebWorker: true,
fileType: '.png',
};
const compressedPic = await imageCompression(pic, options);
console.log('compressed', compressedPic.size);
console.log('compressd pic title', compressedPic.name);
};
In 'browser-image-compression' sources you can see that
@param {string} [options.fileType] - default to be the original mime type from the image file
You should use file mime type rather than .png
extension, so try to use image/png
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With