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.
05/13/2012 at 1:48 PM
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.
05/15/2012 at 5:51 PM
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.
05/02/2013 at 2:54 PM
Can i use J-Exiftool to write tags to non-image files like pdf?
05/02/2013 at 6:08 PM
Theoretically you could, but I’ve never tested it. You’d have to create a new Tag implementation of the PDF tags http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/PDF.html