Java library for reading and writing IPTC metadata

2019-01-23 13:34发布


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.

5条回答
Bombasti
2楼-- · 2019-01-23 13:56

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.

查看更多
何必那么认真
3楼-- · 2019-01-23 14:03

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楼-- · 2019-01-23 14:04

Take a look at IIM4J. Use IIMWriter to write IPTC IIM tags into (jpeg) images.

查看更多
混吃等死
5楼-- · 2019-01-23 14:11

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());
        }           
    }
}
查看更多
家丑人穷心不美
6楼-- · 2019-01-23 14:20

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.

查看更多
登录 后发表回答