@@ -1018,14 +1018,20 @@ public static byte[] sanitizeFile(String inputFilePath, InputFileType inputFileT
10181018 Image initialSizedImage = resizedImage .getScaledInstance (originalWidth , originalHeight , Image .SCALE_SMOOTH );
10191019 // Save image to a bytes buffer
10201020 int bufferedImageType = BufferedImage .TYPE_INT_ARGB ;//By default use a format supporting transparency
1021- if ("jpeg" .equalsIgnoreCase (originalFormat ) || "bmp" .equalsIgnoreCase (originalFormat )) {
1021+ //Sometimes for BMP, the format detected is "bmp; format=compressed"
1022+ if ("jpeg" .equalsIgnoreCase (originalFormat ) || "bmp" .equalsIgnoreCase (originalFormat ) || originalFormat .startsWith ("bmp;" )) {
10221023 bufferedImageType = BufferedImage .TYPE_INT_RGB ;
10231024 }
10241025 BufferedImage sanitizedImage = new BufferedImage (initialSizedImage .getWidth (null ), initialSizedImage .getHeight (null ), bufferedImageType );
10251026 Graphics2D drawer = sanitizedImage .createGraphics ();
10261027 drawer .drawImage (initialSizedImage , 0 , 0 , null );
10271028 drawer .dispose ();
1028- ImageIO .write (sanitizedImage , originalFormat , sanitizedContent );
1029+ //Handle "bmp; format=compressed" case
1030+ String formatToUse = originalFormat ;
1031+ if (formatToUse .startsWith ("bmp;" )) {
1032+ formatToUse = formatToUse .split (";" )[0 ].trim ();
1033+ }
1034+ ImageIO .write (sanitizedImage , formatToUse , sanitizedContent );
10291035 }
10301036 default -> throw new IllegalArgumentException ("Type of file not supported !" );
10311037 }
0 commit comments