wuweihao il y a 3 ans
Parent
commit
8a82100f69

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

@@ -106,6 +106,11 @@
             <!--<artifactId>commons-io</artifactId>-->
         <!--</dependency>-->
 
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-imaging</artifactId>
+        </dependency>
+
 
         <!-- jwt -->
         <dependency>

+ 44 - 6
720yun_local_manage/gis_common/src/main/java/com/gis/common/util/ImgUtils.java

@@ -5,7 +5,11 @@ 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.imaging.ImageInfo;
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.Imaging;
 import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.imageio.ImageIO;
@@ -97,19 +101,37 @@ public class ImgUtils {
 //    }
 
 
+//    public static void checkImgRatio(MultipartFile file){
+//        try {
+//            Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpg");
+//            ImageReader reader = (ImageReader) readers.next();
+//            ImageInputStream iis = ImageIO.createImageInputStream(file);
+//            reader.setInput(iis, true);
+//            int width = reader.getWidth(0);
+//            int height = reader.getHeight(0);
+//
+//            BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
+//
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//
+//    }
+
+
     public static void checkImgRatio(MultipartFile file){
         try {
-            Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpg");
-            ImageReader reader = (ImageReader) readers.next();
-            ImageInputStream iis = ImageIO.createImageInputStream(file);
-            reader.setInput(iis, true);
-            int width = reader.getWidth(0);
-            int height = reader.getHeight(0);
+            ImageInfo imageInfo = Imaging.getImageInfo(file.getInputStream(), null);
+            log.info("正常读取=============================");
+            int width = imageInfo.getWidth();
+            int height = imageInfo.getHeight();
 
             BaseRuntimeException.isHas(!(width/height == 2), null, "非2:1图片");
 
         } catch (IOException e) {
             e.printStackTrace();
+        } catch (ImageReadException e) {
+            e.printStackTrace();
         }
 
     }
@@ -129,4 +151,20 @@ public class ImgUtils {
         }
 
     }
+
+
+    @Test
+    public void test1(){
+        String srcPath = "E:\\桌面\\pano_1x1_素材\\1.jpg";
+        File file = new File(srcPath);
+        try {
+            ImageInfo info = Imaging.getImageInfo(file);
+            System.out.println("width: " + info.getWidth());
+            System.out.println("height: " + info.getHeight());
+        } catch (ImageReadException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
     }

+ 1 - 0
720yun_local_manage/gis_pano/gis_pano.iml

@@ -130,6 +130,7 @@
     <orderEntry type="library" name="Maven: com.belerweb:pinyin4j:2.5.1" level="project" />
     <orderEntry type="library" name="Maven: com.google.zxing:core:3.3.3" level="project" />
     <orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
+    <orderEntry type="library" name="Maven: org.apache.commons:commons-imaging:1.0-alpha3" level="project" />
     <orderEntry type="library" name="Maven: com.auth0:java-jwt:3.2.0" level="project" />
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.2" level="project" />
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.2" level="project" />

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

@@ -126,7 +126,7 @@ public class ProduceServiceImpl implements ProducerService {
             BaseRuntimeException.isHas(!jpg, null,  msg);
 
             // 检查2:1图片
-//            ImgUtils.checkImgRatio(file);
+            ImgUtils.checkImgRatio(file);
             log.info("校验图片完成");
 
         } catch (IOException e) {

+ 17 - 0
720yun_local_manage/pom.xml

@@ -50,6 +50,7 @@
     <aliyun.core.version>4.0.3</aliyun.core.version>
     <aliyun.dysmsapi.version>1.1.0</aliyun.dysmsapi.version>
     <aliyun.oss.version>2.5.0</aliyun.oss.version>
+    <imaging.version>1.0-alpha3</imaging.version>
   </properties>
 
 
@@ -208,7 +209,21 @@
         <!--<version>${commons-io.version}</version>-->
       <!--</dependency>-->
 
+
+      <!--
+          mvn install:install-file -Dfile=commons-imaging-1.0-alpha3.jar -DgroupId=org.apache.commons -DartifactId=commons-imaging -Dversion=1.0-alpha3 -Dpackaging=jar
+      -->
+      <dependency>
+        <groupId>org.apache.commons</groupId>
+        <artifactId>commons-imaging</artifactId>
+        <version>${imaging.version}</version>
+      </dependency>
+
+
+
       <!-- knife4j aip 包-->
+
+
       <dependency>
         <groupId>com.github.xiaoymin</groupId>
         <artifactId>knife4j-spring-boot-starter</artifactId>
@@ -222,6 +237,8 @@
         <version>${shiro.version}</version>
       </dependency>
 
+
+
       <!-- jwt -->
       <dependency>
         <groupId>com.auth0</groupId>