Moving this thread to dev list as it seems to be more appropriate there....
Attached is a patch to the IImageMetadata.java that reflects my revised
proposal thinking this through in conjunction with the proposed solution
in another
<http://mail-archives.apache.org/mod_mbox/commons-dev/201207.mbox/ajax/%3C4FF213A5.3090600%40wellfleetsoftware.com%3E>
thread...
* Add a getMetadataSpecification() method to IImageMetadata so we can
manage the metadata specification that defines the metadata
* Add getMetadata() to nested class IImageMetadataItem to get back at
the parent IImageMetadata instance so we can access the metadata
specification information managed from an IImageMetadata instance
* Add getId(), getName(), getDescription() methods to nested class
IImageMetadataItem. These are the key triplet of info about the
metadata item that is needed in my experience
Of course implementations of these two interfaces would need to also be
updated to support the new methods according to proposed semantics. I
would be happy to contribute in any way that I can and as requested.
Dev team colleagues, please weigh in on the proposal. Thanks for your
awesome work to create this project and for considering this proposal.
On 07/02/2012 07:12 PM, Farrukh Najmi wrote:
Here is a proposed change to the API that would help my scenario...
Modify the org.apache.commons.imaging.common.ImageMetadata$Item class
to have the following additional methods:
* getMetadataSpecification() method that returns a constant String
such as "IPTC:1.1", "EXIF:2.1", "EXIF:2.2"
* getId() method that returns a unique id as follows:
o For EXIF return the Field Name as in Table 3 TIFF Rev. 6.0
Attribute Information Used in Exif in the Exif spec
<http://www.exif.org/Exif2-2.PDF>.
o For IPTC return the IptcRecord..iptcType.getType()
This would allow the first code pattern below to identify each item
based on a specific metadata field defined by a specific specification.
Thoughts?
On 07/02/2012 06:18 PM, Farrukh Najmi wrote:
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
Index: src/main/java/org/apache/commons/imaging/common/IImageMetadata.java
===================================================================
--- src/main/java/org/apache/commons/imaging/common/IImageMetadata.java
(revision 1354112)
+++ src/main/java/org/apache/commons/imaging/common/IImageMetadata.java
(working copy)
@@ -22,8 +22,45 @@
public String toString(String prefix);
public List<? extends IImageMetadataItem> getItems();
+
+ /**
+ * Gets the metadata specification governing this metadata.
+ *
+ * @return "IPTC:1.1" for IPTC 1.1, "EXIF:2.1" for EXIF 2.1, "EXIF:2.2"
for EXIF 2.2, etc.
+ */
+ public String getMetadataSpecification();
public interface IImageMetadataItem {
+
+ /**
+ * Gets the unique identifier for a metadata item as defined by its
governing metadata specification.
+ *
+ * @return The unique identifier. For EXIF it is the 2 byte number
(called tag) to identify the field (e.g. 0x0100). For IPTC this is the XMP
property id (e.g. "CaptionWriter")
+ */
+ public String getId();
+
+ /**
+ * Gets the name for a metadata item as defined by its governing
metadata specification.
+ *
+ * @return The name. For EXIF it is the Field Name (not the Tag Name)
from Table 3 TIFF Rev. 6.0 Attribute Information (e.g. "ImageWidth". For IPTC
this is the "Name" (e.g. "Description Writer").
+ */
+ public String getName();
+
+ /**
+ * Gets the description for a metadata item as defined by its
governing metadata specification.
+ *
+ * @return The description. For EXIF it is the Tag Name (not the Field
Name) from Table 3 TIFF Rev. 6.0 Attribute Information (e.g. "Image width". For
IPTC this is the "Definition" (e.g. "Identifier or the name of the person
involved in writing, editing or correcting the description of
+the content.").
+ */
+ public String getDecsription();
+
+ /**
+ * Gets the parent IImageMetadataItem object.
+ *
+ * @return the parent IImageMetadataItem object.
+ */
+ public IImageMetadata getMetadata();
+
public String toString(String prefix);
public String toString();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org