I deal with a lot of JPEG’s while programming and hence there are times when one has a need to read the header or IPTC metadata of a JPEG, there are various ways to read IPTC metadata but the easiest with few lines of code is using metadata-extractor. Thanks to drewnoakes. here is how it is done using the latest jar version 2.3.1:
try {
IptcReader iptcreader = new IptcReader(new File(“/Path/to/JPEG”));
Iterator itr = iptcreader.extract().getDirectoryIterator();
Tag tag=null;
Iterator itr2;
Directory dir;
while(itr.hasNext()){
dir = (Directory) itr.next();
itr2 = dir.getTagIterator();
while(itr2.hasNext()){
tag =(Tag) itr2.next();
System.out.println(tag.getDescription() + ” — ” + tag.getTagName());
}
}
} catch (Exception ex) {
System.out.println(“Exception : Dteails : ” + ex);
}
Above lines of code prints out all the IPTC tags and its corresponding data on the console
Further Reading:
http://www.barregren.se/blog/how-read-exif-and-iptc-java-image-i-o-api
http://code.google.com/p/metadata-extractor/wiki/GettingStarted