commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Farrukh Najmi <>
Subject [Imaging] Getting EXIF and IPTC metadata using metadata and image format neutral code
Date Mon, 02 Jul 2012 22:18:38 GMT

Hi Guys,

I am trying to use commons-imaging latest svn bits to write a program 
that will read standard metadata such as Exif and IPTC from images in a 
variety of image formats using code that is as image format neutral as 
possible. The goal is to store each class of metadata (e.g. Exif, IPTC, 
...) in a separate Map where the key identifies a metadata attribute 
identifier defined by the standard and a value that is the metadata 
attribute's value.

Here are two patterns I have identified for reading the metadata by 
looking at test programs and code....

1. Read metadata items without considering image format or metadata 

             IImageMetadata metadata = Imaging.getMetadata(is, "Oregon 
Scientific DS6639 - DSC_0307 - iptc added with irfanview.jpg");
             List<? extends IImageMetadata.IImageMetadataItem> items = 

             int i=0;
             for (IImageMetadata.IImageMetadataItem iitem : items) {
                 ImageMetadata.Item item = (ImageMetadata.Item)iitem;
                 System.err.println("Index: " + i + " Key: " + 
item.getKeyword() + " Value: " + item.getText() + " class: " + 
iitem.getClass());   //common.ImageMetadata$Item, Tiff.TiffImageMetadata

This is closest to what I want. The EXIF metadata is represented by 
org.apache.commons.imaging.formats.tiff.TiffImageMetadata$Item and I can 
get at the TiffField and its tagName and value (good). However, IPTC 
metadata is represented by 
org.apache.commons.imaging.common.ImageMetadata$Item. This class seems 
to have no link back to the 
org.apache.commons.imaging.formats.jpeg.iptc.IptcRecord and thus I 
cannot find a way to get the attribute defined by the IPTC spec 

under the IIM mapping rows.

2. Read Exif and IPTC separately using following metadata and image 
format specific  patterns as shown below...

             //Read EXIF
             JpegImageMetadata metadata = (JpegImageMetadata) 
Imaging.getMetadata(is, "Oregon Scientific DS6639 - DSC_0307 - iptc 
added with irfanview.jpg");
             TiffImageMetadata exifMetadata = metadata.getExif();
             List<TiffField> fields = exifMetadata.getAllFields();

             int i=0;
             for (TiffField field : fields) {
                 String key = field.getTagName();
                 Object value = field.getValue();
                 String fieldName =;
                 System.err.println("Index: " + i + " Key: " + key + ", 
Value: " + value + ", valueType: " + value.getClass());

             //Read IPTC
             JpegImageMetadata metadata = (JpegImageMetadata) 
Imaging.getMetadata(is, "Oregon Scientific DS6639 - DSC_0307 - iptc 
added with irfanview.jpg");
             JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
             List oldRecords = psMetadata.photoshopApp13Data.getRecords();

             for (int j = 0; j < oldRecords.size(); j++) {
                 IptcRecord record = (IptcRecord) oldRecords.get(j);
                 System.err.println("Key: " + record.iptcType.getName() 
+ " (0x"
                             + "), value: " + record.value);

Above gives me all the linkage back to specification defined metadata 
fields but is less desirable because it metadata and image format specific.

I feel that it would be ideal to support a generic api that is agnostic 
to metadata and image format but provides a reference back to the 
specification defined field (attribute) identifier some how.

I would very much appreciate some ideas from dev team on how we could 
improve the api to support providing a reference back to a specification 
defined field in a metadata and image format neutral manner.

My apologies if I am missing an obvious solution while I am getting 
familiar with the code.



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message