4

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);
};

Colin
  • 1,112
  • 1
  • 16
  • 27
Shivam Rawat
  • 241
  • 1
  • 4
  • 8

1 Answers1

1

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.

vicacid
  • 509
  • 4
  • 6