Does anyone know some opensource Java library for reading and writing IPTC metadata to JPEG and TIFF? Now I'm using Apache Sanselan. Unfortunately, it can only read IPTC, not write (http://commons.apache.org/sanselan/formatsupport.html).
Will be very grateful for your assistance.
Denis.
问题:
回答1:
Take a look at IIM4J. Use IIMWriter
to write IPTC IIM tags into (jpeg) images.
回答2:
The Apache Commons Imaging (formerly sanselan) has added support for writing IPTC metadata in the svn repo code for their next release. I have verified that this is so in the latest trunk code checked out from svn repo. The code seems stable so I am hoping a release is not too far away. For my project this is good enough.
回答3:
This seems to be quite a old question but following is some helpful info:
reading of metadata such as EXIF,IPTC..etc can be done using Apache Commons Imaging(Formerly Sanselan) or Metadata Extractor(by drew noaks).
writing of metadata can be done using Apache Commons Imaging using following classes:
EXIF - ExifRewriter (http://commons.apache.org/proper/commons-imaging/apidocs/org/apache/commons/imaging/formats/jpeg/exif/ExifRewriter.html)
IPTC - JpegIptcRewriter (http://commons.apache.org/proper/commons-imaging/apidocs/org/apache/commons/imaging/formats/jpeg/iptc/JpegIptcRewriter.html)
XMP - JpegXmpRewriter (http://commons.apache.org/proper/commons-imaging/apidocs/org/apache/commons/imaging/formats/jpeg/xmp/JpegXmpRewriter.html)
回答4:
I've looked myself in the past but not found one. I would suggest looking at an open source project such as http://sourceforge.net/projects/image-tagger/ and see how they do it.
回答5:
For reading metadata I think you should have a look on "metadata-extractor" - an Open Source Project (Apache 2.0 licence) that develops a Java library for reading metadata from image files.
At the moment, this project can get access to the following metadata of images:
- Exif
- IPTC
- XMP
- JFIF / JFXX
- ICC Profiles
- Photoshop fields
The "metadata-extractor" is hosted at google code.
Here is a little straightforward code-example for the 2.4.0 version:
public void example() throws Exception {
File jpegFile = new File("yourJpgFile.jpg");
Metadata metadata = ImageMetadataReader.readMetadata(jpegFile);
Iterator directory = metadata.getDirectoryIterator();
while (directory.hasNext()) {
Object tag = directory.next();
if (tag instanceof ExifDirectory) {
Iterator tags = ((ExifDirectory) tag).getTagIterator();
while (tags.hasNext()) {
System.out.println("EXIF: "+tags.next().toString());
}
} else if (tag instanceof IptcDirectory) {
Iterator tags = ((IptcDirectory) tag).getTagIterator();
while (tags.hasNext()) {
System.out.println("IPTC: "+tags.next().toString());
}
} else if (tag instanceof JpegDirectory) {
Iterator tags = ((JpegDirectory) tag).getTagIterator();
while (tags.hasNext()) {
System.out.println("JPEG: "+tags.next().toString());
}
} else {
System.err.println(tag.getClass());
}
}
}