|
|
@@ -975,15 +975,41 @@ public class CommonUtil {
|
|
|
* @param keepAspectRatio 是否保持原比例
|
|
|
*/
|
|
|
public static void rotateAndScaleImageByThumbnails(InputStream is, OutputStream os, double rotate, String format, double quality, int width, int height, boolean keepAspectRatio) throws IOException {
|
|
|
+ // 标准化输出格式
|
|
|
+ String outputFormat = normalizeFormat(format);
|
|
|
+
|
|
|
Thumbnails.of(is)
|
|
|
.size(width, height)
|
|
|
.keepAspectRatio(keepAspectRatio)
|
|
|
.rotate(rotate)
|
|
|
- .outputFormat(format)
|
|
|
+ .outputFormat(outputFormat)
|
|
|
.outputQuality(quality)
|
|
|
.toOutputStream(os);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 标准化图像格式名称
|
|
|
+ */
|
|
|
+ private static String normalizeFormat(String format) {
|
|
|
+ if (format == null) {
|
|
|
+ return "JPEG"; // 默认格式
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (format.toUpperCase()) {
|
|
|
+ case "JFIF":
|
|
|
+ case "JPEG":
|
|
|
+ case "JPG":
|
|
|
+ return "JPEG";
|
|
|
+ case "PNG":
|
|
|
+ case "GIF":
|
|
|
+ case "BMP":
|
|
|
+ return format.toUpperCase();
|
|
|
+ default:
|
|
|
+ // 对于不支持的格式,返回默认的JPEG格式
|
|
|
+ return "JPEG";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据起止日期获取工作日
|
|
|
*
|