mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
refactor: 根据图片大小设置压缩比优化
This commit is contained in:
parent
9a6c44ee42
commit
77c61b7bde
@ -36,18 +36,22 @@ public class ImgUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 根据图片大小获取压缩比
|
||||
* 根据图片大小设置压缩比
|
||||
*
|
||||
* @param size 图片大小(单位:Bytes)
|
||||
* @return 压缩比例
|
||||
*/
|
||||
public static float getCompressQuality(long size) {
|
||||
if (size <= 0.1 * 1024 * 1024) {
|
||||
return 0.5f;
|
||||
} else if (size > 0.1 * 1024 * 1024 && size <= 1 * 1024 * 1024) {
|
||||
return 0.3f;
|
||||
if (size > 0.1 * 1024 * 1024 && size <= 0.5 * 1024 * 1024) {
|
||||
return 0.8f;
|
||||
} else if (size > 0.5 * 1024 * 1024 && size <= 1 * 1024 * 1024) {
|
||||
return 0.6f;
|
||||
} else if (size > 1 * 1024 * 1024 && size <= 2 * 1024 * 1024) {
|
||||
return 0.4f;
|
||||
} else if (size > 2 * 1024 * 1024 && size <= 5 * 1024 * 1024) {
|
||||
return 0.2f;
|
||||
} else {
|
||||
// 大于1M
|
||||
// 大于5M
|
||||
return 0.1f;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user