|
@@ -90,12 +90,15 @@
|
|
resolve(compressedBlob);
|
|
resolve(compressedBlob);
|
|
} else if (iteration < maxIterations && currentQuality > minQuality) {
|
|
} else if (iteration < maxIterations && currentQuality > minQuality) {
|
|
// 如果还未达到最大迭代次数且质量还可以降低,则递减质量并再次尝试压缩
|
|
// 如果还未达到最大迭代次数且质量还可以降低,则递减质量并再次尝试压缩
|
|
- currentQuality *= 0.8; // 每次迭代降低质量的百分比
|
|
|
|
|
|
+ currentQuality *= 0.7; // 每次迭代降低质量的百分比
|
|
blobFile = compressedBlob; // 使用上一次压缩的结果作为下一次的输入
|
|
blobFile = compressedBlob; // 使用上一次压缩的结果作为下一次的输入
|
|
iteration++; // 增加迭代次数
|
|
iteration++; // 增加迭代次数
|
|
|
|
+ // 打印当前大小和迭代次数
|
|
|
|
+ console.log(`Current Size: ${formatSize(compressedBlob.size)} | Iteration: ${iteration}`);
|
|
attemptCompression().then(resolve).catch(reject);
|
|
attemptCompression().then(resolve).catch(reject);
|
|
} else {
|
|
} else {
|
|
// 如果已经达到最大迭代次数或者质量已经很低,拒绝Promise
|
|
// 如果已经达到最大迭代次数或者质量已经很低,拒绝Promise
|
|
|
|
+ alert("压缩失败,图片太大。");
|
|
reject(new Error("Unable to compress the image to the target size."));
|
|
reject(new Error("Unable to compress the image to the target size."));
|
|
}
|
|
}
|
|
}).catch(reject);
|
|
}).catch(reject);
|