Reading all image metadata from an image file


Reading all image metadata from a file, including all IPTC and EXIF fields:

import com.drew.imaging.*;
import com.drew.metadata.*;
import java.io.*;

public class ReadImageMetadata {
  public static void main(String[] args) throws IOException, ImageProcessingException {
    InputStream imageFile = new FileInputStream(args[0]);
    Metadata metadata = ImageMetadataReader.readMetadata(imageFile);
    System.out.println("read file=" + args[0]);

    for (Directory directory : metadata.getDirectories()) {
      System.out.println("  directory=" + directory);
      for (Tag tag : directory.getTags()) {
        System.out.println("    tag=" + tag);
      }
    }
  }
}

Usage:

$ javac ReadImageMetadata.java \
       -cp xmpcore-5.1.2.jar:metadata-extractor-2.8.1.jar
$ java ReadImageMetadata.java \
       -cp xmpcore-5.1.2.jar:metadata-extractor-2.8.1.jar \
       image.jpg

Licensed under CC BY Creative Commons License ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@hachyderm.io ~ 🐦 @torsteinkrause