P_W999

Because life has no try-catch

J-Exiftool: read and write Exif tags in Java

6 Comments

A while ago I started looking for a Java library which allowed me to read Exif-tags. It quickly turned out that the best implementations relied on the Perl executable ExifTool  by Phil Harvey and a quick look at the documentation told me why: it’s super awesome, it’s super reliable and after many years of development it’s still being updated ! However, this could not be said off the Java libraries which use Exiftool: none of them support writing Exif-tags and only a few are still being developed.

This is where J-ExifTool comes in: it’ll be the first Java-library which allows you to read and write Exif-tags by using the ExifTool  by Phil Harvey. The read functionality is already working pretty okay tough a lot of details are still missing (like formatting and casting the results).

Some of the goals of J-ExifTool are:

  • Java 7
  • High performance for processing batches of images
  • Easy to use
  • Open-Source
  • Well documented and correct code (IntelliJ Code inspection + FindBugs + Checkstyle)
  • A s***-load of logging

If everything is working correctly, reading an Exif-tags using J-ExifTool should be as simple as:

System.setProperty(ExecutionConstant.EXIFTOOLPATH, "lib\\exiftool.exe");
JExifTool tool = new JExifTool();
JExifInfo info = tool.getInfo(new File("D:\\Users\\pw999\\Documents\\Development\\Bitbucket\\j-exiftool\\lib\\DSC00216.JPG"));
String iso = info.get(Tag.ISO);
System.out.println(iso);

Update: if simplified, as suggested by Phil Harvey, the usage of the API. What I’ve started was oriented too much towards batch-processing (internally it still is, but you can’t use it anymore).
What’s left is more easy and straigtforward to use.

About these ads

Author: Phillip

Belgian Java EE consultant, software developer, technology enthusiast and digital photographer.

6 thoughts on “J-Exiftool: read and write Exif tags in Java

  1. Sounds good! Just a couple of questions/comments:

    1) Since “High performance” is a goal, I wanted to be sure you were aware of the exiftool -stay_open feature.

    2) ExifTool tag names may have dashes in them. Is this a problem for the “Tag.ISO” syntax?

    3) The “simple” Java code above still looks complicated to me. I’m just thinking out loud here, but could this be simplified to something more like this?:

    JExifTool tool = new JExifTool(“lib\\exiftool.exe”);
    JExifToolInfo info = tool.extractInfo(new File(“D:\\Users\\pw999\\Documents\\DSC00216.JPG”));
    String iso = info.getValue(“ISO”);
    System.out.println(iso);

    This corresponds roughly to how things are done in the ExifTool Perl API.

    • 1) yes I do :-)
      2) Tag is just an Enum which contains the command line argument and expected data type.
      3) It’s indeed a bit complex, I’m maybe thinking a bit too much in the direction of processing large batches of images.
      Thanks for the input, I’m definately going to use it in some way.

  2. Can i use J-Exiftool to write tags to non-image files like pdf?

  3. This is a very useful and amazing lib. But I cann’t find a way to modify a photo’s shooting time, or a photo which have no shooting time and i wanna to add a shooting time in it.
    Could you give an example code? and Thank you very much! for your reply or email me:”dontpostyourmail”@gmail.com

    • Hey coolcooldool,

      normally, the shooting time is save in the DateTimeOriginal tag (be.pw.jexif.enums.tag.ExifIFD.DATETIMEORIGINAL).
      This is a simple example I copied from my unit tests:

      String date = DateUtil.fromDate(new Date());
      JExifInfo info = tool.getInfo(write01);
      String result = info.setTagValue(ExifIFD.DATETIMEORIGINAL, date);
      

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 30 other followers