|
|
|
|
@ -5,6 +5,9 @@ import java.awt.Image;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
@ -199,6 +202,11 @@ public class AppCmmnUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int MIN_WH = 480;
|
|
|
|
|
public static String getResizeImageTempPath(String path, String prefix) throws Exception {
|
|
|
|
|
byte[] bytes = resizeImage(path);
|
|
|
|
|
return bytesToTempFile(prefix,FilenameUtils.getExtension(path),bytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static byte[] resizeImage(String path) throws Exception {
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
BufferedImage originalImage = ImageIO.read(file);
|
|
|
|
|
@ -268,4 +276,15 @@ public class AppCmmnUtil {
|
|
|
|
|
return newImage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String bytesToTempFile(String prefix, String ext, byte[] baos) throws FileNotFoundException, IOException {
|
|
|
|
|
|
|
|
|
|
String tempDir = System.getProperty("java.io.tmpdir");
|
|
|
|
|
File tempFile = File.createTempFile(prefix+"_", "."+ext, new File(tempDir));
|
|
|
|
|
|
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
|
|
|
|
|
fos.write(baos);
|
|
|
|
|
}
|
|
|
|
|
return tempFile.getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|