import * as imageConversion from 'image-conversion';
//压缩质量
export function getCompressionQuality(isLtSize,imgType) {
  if (isLtSize < 3) {
      return 0.90;
    } else if (isLtSize >= 3 && isLtSize < 5) {
      return 0.80;
    } else if (isLtSize >= 5 && isLtSize < 10) {
      return 0.70;
    } else if (isLtSize >= 10 && isLtSize < 20) {
      return 0.60;
    } else if (isLtSize >= 20 && isLtSize < 30) {
      return 0.50;
    }
  return 0.40;
}
//压缩逻辑
export function compressImage(file, quality) {
  return new Promise((resolve, reject) => {
    imageConversion.compress(file, quality)
      .then((res) => {
        if(res.size / (1024 * 1024)>=2){
          compressImage(res,quality)
          console.log('压缩后体积', res.size / (1024 * 1024));
        }else{
          resolve(res);
        }
      })
      .catch((error) => {
        reject(error);
      });
  });
}

