private String guessImageFormat(String contentType, String imagePath) {

        String format = "png";

        if (contentType == null) {
            contentType = URLConnection.guessContentTypeFromName(imagePath);
        }

        if (contentType != null) {
            format = IMAGE_TYPE_PATTERN.matcher(contentType).replaceFirst("$1");
        }
        else {
            int queryStringIndex = imagePath.indexOf('?');

            if (queryStringIndex != -1) {
                imagePath = imagePath.substring(0, queryStringIndex);
            }

            String[] pathTokens = imagePath.split("\\.");

            if (pathTokens.length > 1) {
                format = pathTokens[pathTokens.length - 1];
            }
        }

        return format;
    }
Attempt to obtain the image format used to write the image from the contentType or the image's file extension.
primefaces/src/main/java/org/primefaces/component/imagecropper/ImageCropperRenderer.java