zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
package org.jeecg.modules.doc.vo;
 
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class ImageOperation {
    private static final Logger log = LoggerFactory.getLogger(ImageOperation.class);
 
    public ImageOperation() {
    }
 
    public static void leftTotation(File inFile, File outFile, int angle) throws IOException {
        Thumbnails.of(new File[]{inFile}).scale(1.0).outputQuality(1.0F).rotate((double)(-angle)).toFile(outFile);
    }
 
    public static void rightTotation(File inFile, File outFile, int angle) throws IOException {
        Thumbnails.of(new File[]{inFile}).scale(1.0).outputQuality(1.0F).rotate((double)angle).toFile(outFile);
    }
 
    public static void thumbnailsImage(File inFile, File outFile, int width, int height) throws IOException {
        Thumbnails.of(new File[]{inFile}).size(width, height).toFile(outFile);
    }
 
    public static InputStream thumbnailsImage(InputStream inputStream, File outFile, int width, int height) throws IOException {
        File parentFile = outFile.getParentFile();
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
 
        ByteArrayOutputStream baos = cloneInputStream(inputStream);
        InputStream inputStream1 = new ByteArrayInputStream(baos.toByteArray());
        InputStream inputStream2 = new ByteArrayInputStream(baos.toByteArray());
        BufferedImage bufferedImage = ImageIO.read(inputStream1);
        if (bufferedImage == null) {
            return inputStream2;
        } else {
            int oriHeight = bufferedImage.getHeight();
            int oriWidth = bufferedImage.getWidth();
            if (oriHeight > height && oriWidth > width) {
                if (oriHeight < oriWidth) {
                    Thumbnails.of(new BufferedImage[]{bufferedImage}).outputQuality(1.0F).scale(1.0).sourceRegion(Positions.CENTER, oriHeight, oriHeight).toFile(outFile);
                } else {
                    Thumbnails.of(new BufferedImage[]{bufferedImage}).outputQuality(1.0F).scale(1.0).sourceRegion(Positions.CENTER, oriWidth, oriWidth).toFile(outFile);
                }
 
                Thumbnails.of(new BufferedImage[]{ImageIO.read(outFile)}).outputQuality(0.9).size(width, height).toFile(outFile);
            } else {
                ImageIO.write(bufferedImage, FilenameUtils.getExtension(outFile.getName()), outFile);
            }
 
            return new FileInputStream(outFile);
        }
    }
 
    public static String getFileExtendName(String fileName) {
        return fileName.lastIndexOf(".") == -1 ? "" : fileName.substring(fileName.lastIndexOf(".") + 1);
    }
 
    private static ByteArrayOutputStream cloneInputStream(InputStream input) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
 
            int len;
            while((len = input.read(buffer)) > -1) {
                baos.write(buffer, 0, len);
            }
 
            baos.flush();
            return baos;
        } catch (IOException var4) {
            var4.printStackTrace();
            return null;
        }
    }
}