|
@@ -857,11 +857,15 @@ public class CommonUtil {
|
|
|
public static byte[] compressImage3(String url) throws IOException, ImageProcessingException, MetadataException {
|
|
|
try(InputStream file = CommonUtil.getOSSInputStream(url)) {
|
|
|
byte[] imageData = InputStreamToBytes(file);
|
|
|
- return compressImage3(imageData);
|
|
|
+ String extension = url.substring(url.lastIndexOf(".") + 1).toUpperCase();
|
|
|
+ if ("JPG".equals(extension) || "JPEG".equals(extension)) {
|
|
|
+ extension = "JPEG";
|
|
|
+ }
|
|
|
+ return compressImage3(imageData, extension);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static byte[] compressImage3(byte[] imageData) throws ImageProcessingException, IOException, MetadataException {
|
|
|
+ public static byte[] compressImage3(byte[] imageData, String formatName) throws ImageProcessingException, IOException, MetadataException {
|
|
|
// 读取原始图像(处理旋转问题)
|
|
|
int orientation = 1;
|
|
|
Metadata metadata = ImageMetadataReader.readMetadata(new ByteArrayInputStream(imageData));
|
|
@@ -873,7 +877,6 @@ public class CommonUtil {
|
|
|
}
|
|
|
}
|
|
|
// 缩放图像
|
|
|
- String formatName = "JPEG";
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
long sizeLimit = 1024*1024*5; //5M 1920 ×1080
|
|
|
int width = 1080;
|