javaexifmetadata-extractor

Determining whether file supports Exif header in Java


I am using Java and the library metadata extractor to work with file metadata.

What I want is to reliably check if a file supports the Exif header (also if it would be supported if it is not available in the header yet).

As far as I know, the Exif header is supported by JPEG and TIFF, and also by some PNGs (among others).

Currently I am just checking the file type for JPEG or TIFF (by using FileTypeDetector::detectFileType), but is it possible to reliably determine whether the file supports the Exif header without checking the file type? Then files of other formats which also support the Exif header could be taken into account, too.

Thanks in advance!


Solution

  • Is it possible to reliably determine whether the file supports the Exif header without checking the file type?

    No. There's no way to "detect" whether a file supports Exif meta data (the term "Exif header" is a misnomer) by inspecting the file. I think your current way of determining the file format, and keep a list of formats you know support Exif makes sense.


    Note that each file format that supports Exif metadata typically wraps it in a "native" (as in the format's own) container structure, so you typically have to add custom code for each format you want to add Exif metadata to. The only exception is TIFF, as Exif metadata is based on the TIFF format. See also Wikipedia on Exif.

    Of course, it is technically possible to append or insert Exif metadata to any file, however, but this will typically render the file corrupt or the Exif metadata will be ignored by other software.