init project
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import imageCompression from "browser-image-compression";
|
||||
|
||||
const PHOTO_MAX_SIZE_MB = 300 / 1024;
|
||||
const PHOTO_MAX_WIDTH_OR_HEIGHT = 1920;
|
||||
|
||||
/**
|
||||
* 压缩上传图片,统一限制到 300 KB。
|
||||
*/
|
||||
export async function compressUploadImage(file: File): Promise<File> {
|
||||
return await imageCompression(file, {
|
||||
maxSizeMB: PHOTO_MAX_SIZE_MB,
|
||||
maxWidthOrHeight: PHOTO_MAX_WIDTH_OR_HEIGHT,
|
||||
useWebWorker: true,
|
||||
initialQuality: .86
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量压缩上传图片。
|
||||
*/
|
||||
export async function compressUploadImageList(fileList: File[]): Promise<File[]> {
|
||||
const result: File[] = [];
|
||||
for (const file of fileList) {
|
||||
result.push(await compressUploadImage(file));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user