7

I am interesting in parsing the exiftool result with a java api or something like that.

I have been researching, but I didn't find any example. For example, how could I get these results in my java project?

ExifTool Version Number : 8.22

File Name : ExifTool.jpg

Directory : t/images File

Size : 24 kB File Modification Date/Time

Etc.. I am looking for a 'how to' or something like that.

sth
  • 222,467
  • 53
  • 283
  • 367
Blanca Hdez
  • 3,513
  • 19
  • 71
  • 93

3 Answers3

7

ExifTool (for Java) is designed to be a simple-to-use and robust Java abstraction of Phil Harvey's ExifTool. I just made the first public release this past week after incubating the project under the imgscalr project umbrella for a while.

The project is under the commercial-friendly Apache 2 license.

My goal for the library isn't just to abstract out the external process execution code from the caller (like most of the other abstraction layers are seeming to do) but to actually design a wrapper so tightly integration and resilient (I will clarify what I mean here later), that you treat instances of your ExifTool class exactly as you would if ExifTool itself was written in Java.

In this initial release I support reading tag data (will add writing in a future release) and it is as simple as this:

File image = // path to some image
ExifTool tool = new ExifTool();

Map<Tag, String> valueMap =
    tool.getImageMeta(image, Tag.GPS_LATITUDE, Tag.GPS_LONGITUDE);

System.out.println("Lat: " + valueMap.get(Tag.GPS_LATITUDE) +
    "\tLong: " + valueMap.get(Tag.GPS_LONGITUDE));

Using ExifTool in the new "daemon mode" (-stay_open True cmd line) is also supported and turning on support for it is as easy as creating your ExifTool instance like so:

ExifTool tool = new ExifTool(Feature.STAY_OPEN);

The documentation on how to use the ExifTool class is extensive, covering everything from design to performance to thread safety.

In addition to making use of ExifTool simple from Java, the class employs a considerable amount of precautions to minimize runtime issues as well as correctly catching and reporting any and all errors that can arise in well-documented ways (instead of letting surprise exceptions bubble up from core Java classes).

I was so pedantic with this exception handling and error recovery because the class is designed to allow you to utilize ExifTool in a high-availability environment like a busy web application. I didn't just want to wrap simple Process objects then throw my hands up in the air if something exploded. I knew myself (and anyone else using the class) would need a well designed API to allow for easy error recovery.

For example, attempting to use ExifTool in daemon mode will cause the class to actually check the underlying install of ExifTool for support for that feature and throw an UnsupportedFeatureException with recommendations on how to work around the problem if it isn't supported.

In addition to the pre-condition checking, to ensure that usage of the class (namely in daemon mode) doesn't leak native OS processes as well as Input/OutputStreams used to communicate with them, the class provides an auto-cleanup thread that after a specified interval of inactivity (default is 10 mins) will shut down the external process cleanly and the read/write streams, making the idle instance of ExifTool lightweight and easy to keep around for re-use.

All the resources are re-initialized on the next call to the class to parse more metadata so there is no need to throw out and re-create new instances. Also the cleanup thread only executes after extended periods of inactivity, not on a set schedule. You can set the interval to anything you want or shut off the cleanup thread completely and manage cleanup yourself (just call close()).

These designs are all part of my ultimate goal of making ExifTool integration into a Java application seamless, performant and easy.

You can check out the main project page for more info on the project, usage, source, download links, etc. or you can jump right to GitHub and look through the code if you prefer.

Riyad Kalla
  • 10,604
  • 7
  • 53
  • 56
  • @chinna_82 it depends on the source image - if you look at the source of ExifTool for Java, TITLE is defined as looking for the "XPTitle" tag data and KEYWORDS (note the 'S') is looking for the "XPKeywords" tag -- you want to make sure your source image has that data in it for that to work. If you need to look for other tags, you can fork the code, define the new ENUM types and use that class. If it works for you, please submit the pull request back to the project and I'll review it and accept it. – Riyad Kalla Jun 14 '14 at 04:09
  • Can it support other than image file.. like AI file or PSD file – chinna_82 Jun 16 '14 at 03:11
  • ExifTool for Java wraps the native 'exiftool' and executes a set of tags against a source file - if Phil's exiftool supports the file, then ExifTool for Java supports it. (in summary: "yes") – Riyad Kalla Jun 17 '14 at 05:39
  • The current actively maintained version of the tool is at https://github.com/mjeanroy/exiftool. – Mr. Lee Aug 05 '19 at 20:34
  • @RiyadKalla much appriciating your efforts, when I visited source code, it seems like the code (or even code of library like im4Java) is strongly dependent on the existance of exifTool on host machine. I mean if ExifTool is not present on the code running platform, this code fails to derive metadata tags, making it platform dependant. Is there any other way to read metadata tags? Note: I used apache Commons imaging library to remove metadata tags, but after removal also I am able to see tags through exifTool. – kAmol Feb 15 '21 at 13:57
  • @kAmol image meta is super complex and varies from vendors even versions over time - there isn't a better battle-tested tool out there than ExifTool - trying to recreate a similarly robust implementation native to Java would be a multi-year undertaking. That's why my library helps make it easy to pull the use of ExifTool directly into a Java app - it's just too good to ignore. – Riyad Kalla Feb 16 '21 at 15:13
3

Check the response in the ExifTool forum:

http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,2697.0.html

Phil Harvey
  • 390
  • 2
  • 4
0

I don't know exiftool, but I have previously used MediaUtil to read and write exif tags in java (I used it for automated jpeg image rotation)

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588