Class ImageSanitizationUtil
java.lang.Object
com.evolveum.midpoint.web.component.input.ImageSanitizationUtil
Provides optional image sanitization, including format conversion and
metadata removal.
Sanitization rewrites the image using
ImageIO. The rewrite does
not preserve the original image metadata.- Author:
- matisovaa
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetFileExtensionFromFileMagicNumber(byte[] fileBytes) Determines file extension by comparing first bytes of file byte array with known magic numbers.static byte[]sanitizeImage(byte[] originalBytes, ImageFormatType convertImageTo, boolean stripMetadata) Applies the requested image processing.
-
Method Details
-
getFileExtensionFromFileMagicNumber
Determines file extension by comparing first bytes of file byte array with known magic numbers.- Parameters:
fileBytes- file byte array to determine file extension- Returns:
- file extension or null if file extension was not possible to determine
-
sanitizeImage
public static byte[] sanitizeImage(byte[] originalBytes, ImageFormatType convertImageTo, boolean stripMetadata) throws ImageSanitizationException Applies the requested image processing. If neither conversion nor metadata stripping is requested, the original byte array is returned unchanged. Otherwise, the image is read and written again. When no target format is specified, the original format detected from the magic number is preserved.- Parameters:
originalBytes- image content to processconvertImageTo- requested output format, ornullto preserve the detected original formatstripMetadata- whether the image should be rewritten to remove metadata- Returns:
- processed image content, original content if processing is not
requested, or
nullif the input isnull - Throws:
ImageSanitizationException- if the image format cannot be determined or the image cannot be read or written
-