|
@@ -1,13 +1,16 @@
|
|
|
package com.gis.common.util;
|
|
|
|
|
|
+import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import com.gis.common.base.exception.BaseRuntimeException;
|
|
|
import com.gis.common.constant.CmdConstant;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
/**
|
|
@@ -16,7 +19,7 @@ import java.io.IOException;
|
|
|
* 图片工具类
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-public class ImgUtil {
|
|
|
+public class ImgUtils {
|
|
|
|
|
|
/**
|
|
|
* 202-03-27
|
|
@@ -49,18 +52,38 @@ public class ImgUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// public static void checkImgRatio(MultipartFile file){
|
|
|
+//
|
|
|
+// try {
|
|
|
+// BufferedImage read = ImgUtil.read(file.getInputStream());
|
|
|
+// int width = read.getWidth();
|
|
|
+// int height = read.getHeight();
|
|
|
+// BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
* 检查2:1图片
|
|
|
* @param file
|
|
|
*/
|
|
|
public static void checkImgRatio(MultipartFile file){
|
|
|
+ BufferedImage read = null;
|
|
|
try {
|
|
|
- BufferedImage read = cn.hutool.core.img.ImgUtil.read(file.getInputStream());
|
|
|
+ read = ImgUtil.read(file.getInputStream());
|
|
|
int width = read.getWidth();
|
|
|
int height = read.getHeight();
|
|
|
BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (read != null){
|
|
|
+ // 释放内存
|
|
|
+ read.getGraphics().dispose();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|