Class ImageMetadataReader

java.lang.Object
com.drew.imaging.ImageMetadataReader

public class ImageMetadataReader extends Object
Reads metadata from any supported file format.

This class a lightweight wrapper around other, specific metadata processors. During extraction, the file type is determined from the first few bytes of the file. Parsing is then delegated to one of:

If you know the file type you're working with, you may use one of the above processors directly. For most scenarios it is simpler, more convenient and more robust to use this class.

FileTypeDetector is used to determine the provided image's file type, and therefore the appropriate metadata reader to use.

Author:
Drew Noakes https://drewnoakes.com
  • Method Details

    • readMetadata

      public static Metadata readMetadata(InputStream inputStream) throws ImageProcessingException, IOException
      Reads metadata from an InputStream.
      Parameters:
      inputStream - a stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.
      Returns:
      a populated Metadata object containing directories of tags with values and any processing errors.
      Throws:
      ImageProcessingException - if the file type is unknown, or for general processing errors.
      IOException
    • readMetadata

      public static Metadata readMetadata(InputStream inputStream, long streamLength) throws ImageProcessingException, IOException
      Reads metadata from an InputStream of known length.
      Parameters:
      inputStream - a stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.
      streamLength - the length of the stream, if known, otherwise -1.
      Returns:
      a populated Metadata object containing directories of tags with values and any processing errors.
      Throws:
      ImageProcessingException - if the file type is unknown, or for general processing errors.
      IOException
    • readMetadata

      public static Metadata readMetadata(InputStream inputStream, long streamLength, FileType fileType) throws IOException, ImageProcessingException
      Reads metadata from an InputStream of known length and file type.
      Parameters:
      inputStream - a stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.
      streamLength - the length of the stream, if known, otherwise -1.
      fileType - the file type of the data stream.
      Returns:
      a populated Metadata object containing directories of tags with values and any processing errors.
      Throws:
      ImageProcessingException - if the file type is unknown, or for general processing errors.
      IOException
    • readMetadata

      public static Metadata readMetadata(File file) throws ImageProcessingException, IOException
      Reads Metadata from a File object.
      Parameters:
      file - a file from which the image data may be read.
      Returns:
      a populated Metadata object containing directories of tags with values and any processing errors.
      Throws:
      ImageProcessingException - for general processing errors.
      IOException
    • main

      public static void main(String[] args)
      An application entry point. Takes the name of one or more files as arguments and prints the contents of all metadata directories to System.out.

      If -thumb is passed, then any thumbnail data will be written to a file with name of the input file having .thumb.jpg appended.

      If -markdown is passed, then output will be in markdown format.

      If -hex is passed, then the ID of each tag will be displayed in hexadecimal.

      Parameters:
      args - the command line arguments