Wednesday, September 15, 2010

Java and EXIF data

I have recently needed to try to read EXIF data from Java. Easier said than done, unfortunately, and finding out how was not easy.

A few months ago I dug up what looked like a good approach, but it's old code (~2002), and calls classes/methods that are no longer accessible. I think they're still present in the runtime, but you can't use them yourself.

So I went hunting again, today. Found something called Imagero, which claimed to read the EXIF, but it didn't really look like it did, and the license statement was too burdensome.

Something called JExifViewer also looks good. It's a little bit too much GUI as opposed to callable functions, but it does seem to work ok.

I also found this:

Java Forum Link

which explains how to do it relatively easily.

The key thing is that you have to install a separate tool (the TIFF tool), and that turns out to have a quirk in that there are multiple variations, and you really need to install the JDK variation *and* the JRE version, because you probably aren't running your code in Eclipse from the runtime in the JDK.

Anyway, the code in the forum works great, does exactly what you are hoping for, and this code is way smaller once you install the other library (which comes from Sun anyway, so it's a good thing to go ahead and do).

The only flaw with all this is that EXIF data is most non-standardized, there are implementation inconsistencies...you know the drill, and it only applies to a few file formats, primarily JPG.

-----------

Later: well, this bit of java code is less than perfect. I was able to break it pretty quickly.

Looks like "exiftool" is the better approach, as a callable program.

No comments: