ExifTool – Enhanced Java Integration for ExifTool

Sections

  1. Description
  2. License
  3. What Problem Does this Solve?
  4. Benefits
  5. Usage
  6. Intended Audience
  7. Download
  8. Javadoc & Source
  9. Maven
  10. Bug Reports
  11. Feature Requests, Comments & Feedback
See ExifTool in action here!

Description

This project represents a robust and seamless Java integration with Phil Harvey’s Perl-based ExifTool.

The goal of this project is to provide a well design and performant integration with ExifTool such that integration of ExifTool into any Java application feels completely natural; like using any other Java library where all the concerns of interacting with an external process and/or the more complex concepts in ExifTool itself are abstracted away into simple, Java-provided constructs (e.g. enums, Maps, name/value pairs, etc.)

Even the use of more complex features of ExifTool, like “daemon mode”, are abstracted away by this project and simplified into a single line of code change for the caller to take advantage of with no concern for leaking host OS processes or streams; this Java integration will take care of all of that for you automatically.

The set of EXIF tags supported out of the box is based on the EXIF tags supported
by the most popular mobile devices (iPhone, Android, BlackBerry, etc.) as well
as some of the most popular cameras on the market (Canon point and shoot as well
as DSLR).

And lastly, to ensure that integration with the external ExifTool project is as
robust and seamless as possible, this class also offers extensive pre-condition
checking and error reporting during instantiation and use.

For example, if you specify that you want to use Feature.STAY_OPEN support, the
ExifTool class will actually check the native ExifTool executable for support
for that feature before allowing the feature to be turned on and report the
problem to the caller along with potential work-arounds if necessary.

Additionally, all external calls to the process are safely wrapped and reported
with detailed exceptions if problems arise instead of just letting unknown
exceptions bubble up from the unknown system depths to the caller.

All the exceptions and exceptional scenarios are well-documented in the Javadoc
along with extensive implementation details for anyone wanting to know more about
the project.

License

This software is licensed under the Apache 2 License.

What Problem Does this Solve?

Extracting metadata from images (namely EXIF, IPTC and XMP) requires a good library. Unfortunately in Java there is not much of a robust selection with only one library even coming close.

Outside of the Java realm, far and away the most functional metadata extraction piece of software in existence is Phil Harvey’s ExifTool.

ExifTool has been in development for 8 years, covers support for all official tag specs as well as proprietary manufacturer tags and supports reading and writing tags to almost every image and video file format you can think of. It also happens to be the software Flickr uses to process all uploaded images since 2009; roughly 3 billion images processed with ExifTool so far (confirmed by author Phil Harvey).

It is easy to see why an image-processing app in Java would want to take advantage of such a powerful tool.

Unfortunately the existing integrations with ExifTool in Java are very limited.

This project provides robust, seamless and performant integration with Phil Harvey’s ExifTool, making it trivial to take advantage of the unmatched power of ExifTool in your Java application.

No need to worry about external process execution, error handling or knowing the right command line switches to take advantage of ExifTool. This class abstracts away everything and allows you to make simple calls to get the metadata you want out of the images you have.

Benefits

  • Robust, resilient code that checks required pre-conditions before running and notifies you of solutions to problems it finds.
  • Automatic cleanup thread used for cleaning up stray OS processes and internal stream resources when using ExifTool in daemon mode; takes the burden off of you for working with a native process.
  • Performant code, minimizing unnecessary object creation and optimized for use in long-running web application environments.
  • Abstracts away the complexities of using the more advanced features of ExifTool (like daemon mode) automatically so use stays simple.
  • Integrates with ExifTool on any platforms (Linux, Windows, Mac).
  • Extremely detailed logging can be enabled to get insight into how the tool is working and performing.
  • Documented (both Javadoc and source docs) to a fault to extension and use of the class easy.

Usage

Usage is straight forward, let’s say we wanted to get the GPS coordinates out of an image:

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) +
		 ", Long: " + valueMap.get(Tag.GPS_LONGITUDE));

The fundamentals of use is that you give ExifTool a File handle to the image you
want to query as well as a list of Tags you want to pull values from it for and
it will give you back the results in a Map.

If you want to use ExifTool in daemon mode, you only change one line:

ExifTool tool = new ExifTool(Feature.STAY_OPEN);

and then keep that “tool” reference around and re-use it as necessary. Under the
covers the ExifTool class will re-use the same ExifTool process for all the queries,
usually taking 1/20th or 1/30th the time to complete.

TIP: ExifTool provides an automatic cleanup thread that, by default, will cleanup the native ExifTool process and internal read/write streams used to communicate with it after 10mins of inactivity. You can adjust this inactivity interval OR disable the auto-cleanup completely by setting the exiftool.processCleanupDelay system property.

Intended Audience

Any Java developer (client side app, server side app, etc.) that wants to extract metadata from images utilizing the power of ExifTool.

Download

You still need the native ExifTool executable for your platform.

All download bundles include the library JAR, source code and Javadoc.

Javadoc & Source Code

Maven

The Buzz Media provides access to it’s libraries via it’s own Maven Repository. Sources and Javadoc are available from the repository.

Edit your pom.xml and add the following to your <repositories> section (be sure to add one if you don’t have one already):

<repository>
	<id>The Buzz Media Maven Repository</id>
	<url>http://maven.thebuzzmedia.com</url>
</repository>

Then edit your pom.xml and add the following dependency to your <dependencies> section (be sure to add one if you don’t have one already):

<dependency>
	<groupId>com.thebuzzmedia</groupId>
	<artifactId>exiftool-lib</artifactId>
	<version>1.1</version>
	<type>jar</type>
	<scope>compile</scope>
</dependency>

Be sure to adjust the version value to whichever version of ExifTool you want to grab.

You still need the native ExifTool executable for your platform.

NOTE: At this time we are not providing checksums for the files on our repository, so you will see “[WARNING] Checksum validation failed” messages from Maven, but they can be safely ignored. Writing a release POM for Maven is beyond my capabilities as a human at this time.

Projects Using ExifTool

Bug Reports

If you find a bug, please create a new issue with a description of the problem and how to reproduce it. Example files help a lot!

Feature Requests, Comments & Feedback

Please email me at software@thebuzzmedia.com, I would love to hear from you.