|
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.IOException;
|
|
|
|
|
@@ -69,19 +70,16 @@ public class ImgUtils {
|
|
|
* @param file
|
|
|
*/
|
|
|
public static void checkImgRatio(MultipartFile file){
|
|
|
- BufferedImage read = null;
|
|
|
try {
|
|
|
- read = ImgUtil.read(file.getInputStream());
|
|
|
+
|
|
|
+ BufferedImage read = ImageIO.read(file.getInputStream());
|
|
|
int width = read.getWidth();
|
|
|
int height = read.getHeight();
|
|
|
+ // 释放内存
|
|
|
+ read.getGraphics().dispose();
|
|
|
BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- } finally {
|
|
|
- if (read != null){
|
|
|
- // 释放内存
|
|
|
- read.getGraphics().dispose();
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
}
|