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
standard.
IImageMetadata metadata = Imaging.getMetadata(is, "Oregon
Scientific DS6639 - DSC_0307 - iptc added with irfanview.jpg");
List<? extends IImageMetadata.IImageMetadataItem> items =
metadata.getItems();
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
i++;
}
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
<http://www.iptc.org/std/photometadata/2008/specification/IPTC-PhotoMetadata-2008.pdf>
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 = field.tagInfo.name;
System.err.println("Index: " + i + " Key: " + key + ",
Value: " + value + ", valueType: " + value.getClass());
i++;
}
//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"
+
Integer.toHexString(record.iptcType.getType())
+ "), 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.
--
Regards,
Farrukh
Web: http://www.wellfleetsoftware.com