wuweihao преди 3 години
родител
ревизия
87171ae6dd

+ 5 - 0
720yun_local_manage/gis_common/pom.xml

@@ -101,6 +101,11 @@
             <artifactId>commons-lang3</artifactId>
         </dependency>
 
+        <!--<dependency>-->
+            <!--<groupId>commons-io</groupId>-->
+            <!--<artifactId>commons-io</artifactId>-->
+        <!--</dependency>-->
+
 
         <!-- jwt -->
         <dependency>

+ 25 - 2
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/ImgUtil.java

@@ -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();
+            }
         }
 
     }

+ 6 - 5
720yun_local_manage/gis_pano_producer/src/main/java/com/gis/cms/service/impl/ProduceServiceImpl.java

@@ -1,8 +1,10 @@
 package com.gis.cms.service.impl;
 
 
+import cn.hutool.core.img.ImgUtil;
 import cn.hutool.core.io.FileTypeUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.IoUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.gis.cms.config.RabbitConfig;
 import com.gis.cms.entity.po.FodderEntity;
@@ -17,10 +19,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletRequest;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
 
 /**
@@ -121,11 +125,8 @@ public class ProduceServiceImpl implements ProducerService {
             BaseRuntimeException.isHas(!jpg, null,  msg);
 
             // 检查2:1图片
-//            BufferedImage read = cn.hutool.core.img.ImgUtil.read(file.getInputStream());
-//            int width = read.getWidth();
-//            int height = read.getHeight();
-//            BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
-//            log.info("校验图片完成");
+            ImgUtils.checkImgRatio(file);
+            log.info("校验图片完成");
 
         } catch (IOException e) {
             e.printStackTrace();

+ 9 - 0
720yun_local_manage/pom.xml

@@ -39,6 +39,7 @@
     <lombok.version>1.18.2</lombok.version>
     <fastjson.version>1.2.75</fastjson.version>
     <lang3.version>3.7</lang3.version>
+    <commons-io.version>2.7</commons-io.version>
     <knife4j.version>2.0.2</knife4j.version>
     <mysql.version>8.0.15</mysql.version>
     <druid.version>1.2.6</druid.version>
@@ -192,6 +193,8 @@
       </dependency>
 
 
+
+
       <!-- StringUtils -->
       <dependency>
         <groupId>org.apache.commons</groupId>
@@ -199,6 +202,12 @@
         <version>${lang3.version}</version>
       </dependency>
 
+      <!--<dependency>-->
+        <!--<groupId>commons-io</groupId>-->
+        <!--<artifactId>commons-io</artifactId>-->
+        <!--<version>${commons-io.version}</version>-->
+      <!--</dependency>-->
+
       <!-- knife4j aip 包-->
       <dependency>
         <groupId>com.github.xiaoymin</groupId>