瀏覽代碼

修改退件等级上传图片的压缩比例和最大最小图片限制

zengjun 2 周之前
父節點
當前提交
1b20e19d8d
共有 2 個文件被更改,包括 7 次插入7 次删除
  1. 6 6
      src/utils/imageCompression.ts
  2. 1 1
      src/utils/imageFormat.ts

+ 6 - 6
src/utils/imageCompression.ts

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

+ 1 - 1
src/utils/imageFormat.ts

@@ -35,7 +35,7 @@ export async function convertHeicHeifToWebp(file: File): Promise<File> {
     const result = await heic2any({
       blob: file,
       toType: 'image/webp',
-      quality: 0.92,
+      quality: 1,
     })
 
     const blob = Array.isArray(result) ? result[0] : result