|
|
@@ -15,7 +15,7 @@ async function compressImageToTargetSize(
|
|
|
file: File,
|
|
|
targetMinSize: number,
|
|
|
targetMaxSize: number,
|
|
|
- quality: number = 1
|
|
|
+ quality: number = 0.9
|
|
|
): Promise<File> {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const canvas = document.createElement('canvas')
|
|
|
@@ -236,8 +236,8 @@ function compressWithHigherQuality(
|
|
|
*/
|
|
|
export async function compressImage(
|
|
|
file: File,
|
|
|
- maxSize: number = 5 * 1024 * 1024,
|
|
|
- quality: number = 1
|
|
|
+ maxSize: number = 1 * 1024 * 1024,
|
|
|
+ quality: number = 0.9
|
|
|
): Promise<File> {
|
|
|
// 如果文件小于等于最大限制,直接返回原文件
|
|
|
if (file.size <= maxSize) {
|
|
|
@@ -245,8 +245,8 @@ export async function compressImage(
|
|
|
}
|
|
|
|
|
|
// 对于大于1MB的文件,设置目标大小为0.8MB-1MB之间
|
|
|
- const targetMinSize = 1024 * 1024// 1MB
|
|
|
- const targetMaxSize = maxSize // 5MB
|
|
|
+ const targetMinSize = 800 * 1024 // 800KB
|
|
|
+ const targetMaxSize = maxSize // 1MB
|
|
|
return compressImageToTargetSize(file, targetMinSize, targetMaxSize, quality)
|
|
|
}
|
|
|
|
|
|
@@ -259,7 +259,7 @@ export async function compressImage(
|
|
|
*/
|
|
|
export async function compressImages(
|
|
|
files: File[],
|
|
|
- maxSize: number = 5 * 1024 * 1024,
|
|
|
+ maxSize: number = 1 * 1024 * 1024,
|
|
|
quality: number = 0.8
|
|
|
): Promise<File[]> {
|
|
|
const results: File[] = []
|