Prechádzať zdrojové kódy

质检影像资料保存-webp文件改为png会无法读取,导致模板生成出来没有图片,增加webp转换png

qianxb 3 mesiacov pred
rodič
commit
a396769dba

+ 13 - 1
blade-ops/blade-resource/src/main/java/org/springblade/resource/feign/CommonFileClientImpl.java

@@ -4,6 +4,7 @@ import com.aspose.cells.SaveFormat;
 import com.aspose.words.DocumentBuilder;
 import com.itextpdf.text.Image;
 import com.itextpdf.text.Rectangle;
+import com.itextpdf.text.Utilities;
 import com.itextpdf.text.pdf.PdfWriter;
 import lombok.AllArgsConstructor;
 import org.apache.pdfbox.pdmodel.PDDocument;
@@ -18,6 +19,10 @@ import org.springblade.resource.vo.NewBladeFile;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.stream.FileImageInputStream;
+import java.awt.image.BufferedImage;
 import java.io.*;
 import java.util.List;
 import java.util.Objects;
@@ -45,7 +50,12 @@ public class CommonFileClientImpl implements CommonFileClient {
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
             PdfWriter.getInstance(document, bos);
             document.open();
-            Image image = Image.getInstance(this.InputStreamToBytes(file.getInputStream()));
+            byte[] bytes = IoUtil.readToByteArray(file.getInputStream());
+            if (bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70){
+                bytes = CommonUtil.webpToPngBytes(file.getInputStream());
+            }
+            Image image = Image.getInstance(bytes);
+
             // 设置页面宽高与图片一致
             document.setPageSize(new Rectangle(image.getScaledWidth(), image.getScaledHeight()));
             // 图片居中(感觉没啥用)
@@ -78,6 +88,8 @@ public class CommonFileClientImpl implements CommonFileClient {
         return newBladeFile;
     }
 
+
+
     /**
      * 获取字节数组
      */

+ 3 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/ImageClassificationFileController.java

@@ -232,6 +232,9 @@ public class ImageClassificationFileController extends BladeController {
 
                                                 //获取文件流
                                                 byte[] bytes = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(urls.get(i)));
+                                                if (bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70){
+                                                    bytes = CommonUtil.webpToPngBytes(CommonUtil.getOSSInputStream(urls.get(i)));
+                                                }
 
                                                 //压缩文件大小
                                                 byte[] byteNew = FileUtils.compressImage(bytes);