Class ExifReader


  • public final class ExifReader
    extends java.lang.Object
    Read out EXIF information from a JPEG file
    Since:
    99
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ExifReader()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.geom.AffineTransform getRestoreOrientationTransform​(int orientation, int width, int height)
      Returns a Transform that fixes the image orientation.
      static boolean orientationNeedsCorrection​(int orientation)
      Check, if the given orientation requires any correction to the image.
      static boolean orientationSwitchesDimensions​(int orientation)
      Check, if the given orientation switches width and height of the image.
      private static double readAxis​(com.drew.metadata.exif.GpsDirectory dirGps, int gpsTag, int gpsTagRef, char cRef)  
      static java.lang.String readCaption​(com.drew.metadata.iptc.IptcDirectory dirIptc)
      Returns the caption of the given IPTC directory.
      static java.lang.Double readDirection​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the direction of the given EXIF GPS directory.
      static java.lang.Double readDirection​(java.io.File filename)
      Returns the direction of the given JPEG file.
      static java.lang.Double readElevation​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the elevation of the given EXIF GPS directory.
      static java.lang.Double readElevation​(java.io.File filename)
      Returns the elevation of the given JPEG file.
      static java.lang.String readGpsDatum​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the GPS datum value of the given EXIF GPS directory.
      static java.lang.String readGpsDatum​(java.io.File filename)
      Returns the GPS datum value of the given JPEG file.
      static java.lang.Integer readGpsDiffMode​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the GPS differential mode of the given EXIF GPS directory.
      static java.lang.Integer readGpsDiffMode​(java.io.File filename)
      Returns the GPS differential mode of the given JPEG file.
      static java.lang.Double readGpsDop​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the GPS DOP value of the given EXIF GPS directory.
      static java.lang.Double readGpsDop​(java.io.File filename)
      Returns the GPS DOP value of the given JPEG file.
      static java.time.Instant readGpsInstant​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the GPS date/time from the given JPEG file.
      static java.time.Instant readGpsInstant​(java.io.File filename)
      Returns the GPS date/time from the given JPEG file.
      static java.lang.Integer readGpsMeasureMode​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the GPS 2d/3d mode of the given EXIF GPS directory.
      static java.lang.Integer readGpsMeasureMode​(java.io.File filename)
      Returns the GPS 2d/3d mode of the given JPEG file.
      static java.lang.String readGpsProcessingMethod​(com.drew.metadata.exif.GpsDirectory dirGps)
      Return the GPS processing method of the given EXIF GPS directory.
      static java.lang.String readGpsProcessingMethod​(java.io.File filename)
      Return the GPS processing method of the given JPEG file.
      static java.lang.Double readGpsTrackDirection​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the GPS track direction of the given EXIF GPS directory.
      static java.lang.Double readGpsTrackDirection​(java.io.File filename)
      Returns the GPS track direction of the given JPEG file.
      static java.lang.String readHeadline​(com.drew.metadata.iptc.IptcDirectory dirIptc)
      Returns the headline of the given IPTC directory.
      static java.lang.Double readHpositioningError​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the GPS horizontal positionning error of the given EXIF GPS directory.
      static java.lang.Double readHpositioningError​(java.io.File filename)
      Returns the GPS horizontal positionning error of the given JPEG file.
      static java.time.Instant readInstant​(com.drew.metadata.Metadata metadata)
      Returns the date/time from the given JPEG file.
      static java.time.Instant readInstant​(java.io.File filename)
      Returns the date/time from the given JPEG file.
      static java.util.List<java.lang.String> readKeywords​(com.drew.metadata.iptc.IptcDirectory dirIptc)
      Returns the keywords of the given IPTC directory.
      static LatLon readLatLon​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the geolocation of the given EXIF GPS directory.
      static LatLon readLatLon​(java.io.File filename)
      Returns the geolocation of the given JPEG file.
      static java.lang.String readObjectName​(com.drew.metadata.iptc.IptcDirectory dirIptc)
      Returns the object name of the given IPTC directory.
      static java.lang.Integer readOrientation​(java.io.File filename)
      Returns the image orientation of the given JPEG file.
      static java.lang.Double readSpeed​(com.drew.metadata.exif.GpsDirectory dirGps)
      Returns the speed of the given EXIF GPS directory.
      static java.lang.Double readSpeed​(java.io.File filename)
      Returns the speed of the given JPEG file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • readInstant

        public static java.time.Instant readInstant​(java.io.File filename)
        Returns the date/time from the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The date/time read in the EXIF section, or null if not found
      • readInstant

        public static java.time.Instant readInstant​(com.drew.metadata.Metadata metadata)
        Returns the date/time from the given JPEG file.
        Parameters:
        metadata - The EXIF metadata
        Returns:
        The date/time read in the EXIF section, or null if not found
      • readGpsInstant

        public static java.time.Instant readGpsInstant​(java.io.File filename)
        Returns the GPS date/time from the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS date/time read in the EXIF section, or null if not found
        Since:
        19387
      • readGpsInstant

        public static java.time.Instant readGpsInstant​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the GPS date/time from the given JPEG file.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The GPS date/time read in the EXIF section, or null if not found
        Since:
        19387
      • readOrientation

        public static java.lang.Integer readOrientation​(java.io.File filename)
        Returns the image orientation of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The image orientation as an int. Default value is 1. Possible values are listed in EXIF spec as follows:
        1. The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side.
        2. The 0th row is at the visual top of the image, and the 0th column is the visual right-hand side.
        3. The 0th row is at the visual bottom of the image, and the 0th column is the visual right-hand side.
        4. The 0th row is at the visual bottom of the image, and the 0th column is the visual left-hand side.
        5. The 0th row is the visual left-hand side of the image, and the 0th column is the visual top.
        6. The 0th row is the visual right-hand side of the image, and the 0th column is the visual top.
        7. The 0th row is the visual right-hand side of the image, and the 0th column is the visual bottom.
        8. The 0th row is the visual left-hand side of the image, and the 0th column is the visual bottom.
        See Also:
        http://www.impulseadventure.com/photo/exif-orientation.html, http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto
      • readLatLon

        public static LatLon readLatLon​(java.io.File filename)
        Returns the geolocation of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The lat/lon read in the EXIF section, or null if not found
        Since:
        6209
      • readLatLon

        public static LatLon readLatLon​(com.drew.metadata.exif.GpsDirectory dirGps)
                                 throws com.drew.metadata.MetadataException
        Returns the geolocation of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The lat/lon read in the EXIF section, or null if dirGps is null
        Throws:
        com.drew.metadata.MetadataException - if invalid metadata is given
        Since:
        6209
      • readDirection

        public static java.lang.Double readDirection​(java.io.File filename)
        Returns the direction of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The direction of the image when it was captures (in degrees between 0.0 and 359.99), or null if not found
        Since:
        6209
      • readDirection

        public static java.lang.Double readDirection​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the direction of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The direction of the image when it was captured (in degrees between 0.0 and 359.99), or null if missing or if dirGps is null
        Since:
        6209
      • readGpsTrackDirection

        public static java.lang.Double readGpsTrackDirection​(java.io.File filename)
        Returns the GPS track direction of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS track direction of the image when it was captures (in degrees between 0.0 and 359.99), or null if not found
        Since:
        19387
      • readGpsTrackDirection

        public static java.lang.Double readGpsTrackDirection​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the GPS track direction of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The GPS track direction of the image when it was captured (in degrees between 0.0 and 359.99), or null if missing or if dirGps is null
        Since:
        19387
      • readAxis

        private static double readAxis​(com.drew.metadata.exif.GpsDirectory dirGps,
                                       int gpsTag,
                                       int gpsTagRef,
                                       char cRef)
                                throws com.drew.metadata.MetadataException
        Throws:
        com.drew.metadata.MetadataException
      • readSpeed

        public static java.lang.Double readSpeed​(java.io.File filename)
        Returns the speed of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The speed of the camera when the image was captured (in km/h), or null if not found
        Since:
        11745
      • readSpeed

        public static java.lang.Double readSpeed​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the speed of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The speed of the camera when the image was captured (in km/h), or null if missing or if dirGps is null
        Since:
        11745
      • readElevation

        public static java.lang.Double readElevation​(java.io.File filename)
        Returns the elevation of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The elevation of the camera when the image was captured (in m), or null if not found
        Since:
        11745
      • readElevation

        public static java.lang.Double readElevation​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the elevation of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The elevation of the camera when the image was captured (in m), or null if missing or if dirGps is null
        Since:
        11745
      • readHpositioningError

        public static java.lang.Double readHpositioningError​(java.io.File filename)
        Returns the GPS horizontal positionning error of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS horizontal positionning error of the camera when the image was captured (in m), or null if not found
        Since:
        19387
      • readHpositioningError

        public static java.lang.Double readHpositioningError​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the GPS horizontal positionning error of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The GPS horizontal positionning error of the camera when the image was captured (in m), or null if missing or if dirGps is null
        Since:
        19387
      • readGpsDiffMode

        public static java.lang.Integer readGpsDiffMode​(java.io.File filename)
        Returns the GPS differential mode of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS differential mode of the camera when the image was captured,
        • 0 : no differential correction
        • 1 : differential correction
        • or null if not found
        Since:
        19387
      • readGpsDiffMode

        public static java.lang.Integer readGpsDiffMode​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the GPS differential mode of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The GPS differential mode of the camera when the image was captured,
        • 0 : no differential correction
        • 1 : differential correction
        • or null if missing or if dirGps is null
        Since:
        19387
      • readGpsMeasureMode

        public static java.lang.Integer readGpsMeasureMode​(java.io.File filename)
        Returns the GPS 2d/3d mode of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS 2d/3d mode of the camera when the image was captured,
        • 2 : 2d mode
        • 2 : 3d mode
        • or null if not found
        Since:
        19387
      • readGpsMeasureMode

        public static java.lang.Integer readGpsMeasureMode​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the GPS 2d/3d mode of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The 2d/3d mode of the camera when the image was captured,
        • 2 : 2d mode
        • 3 : 3d mode
        • or null if missing or if dirGps is null
        Since:
        19387
      • readGpsDop

        public static java.lang.Double readGpsDop​(java.io.File filename)
        Returns the GPS DOP value of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS DOP value of the camera when the image was captured, or null if not found
        Since:
        19387
      • readGpsDop

        public static java.lang.Double readGpsDop​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the GPS DOP value of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The GPS DOP value of the camera when the image was captured, or null if missing or if dirGps is null
        Since:
        19387
      • readGpsDatum

        public static java.lang.String readGpsDatum​(java.io.File filename)
        Returns the GPS datum value of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS datum value of the camera when the image was captured, or null if not found
        Since:
        19387
      • readGpsDatum

        public static java.lang.String readGpsDatum​(com.drew.metadata.exif.GpsDirectory dirGps)
        Returns the GPS datum value of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The GPS datum value of the camera when the image was captured, or null if missing or if dirGps is null
        Since:
        19387
      • readGpsProcessingMethod

        public static java.lang.String readGpsProcessingMethod​(java.io.File filename)
        Return the GPS processing method of the given JPEG file.
        Parameters:
        filename - The JPEG file to read
        Returns:
        The GPS processing method. Possible values from the EXIF specs are:
        • GPS
        • QZSS
        • GALILEO
        • GLONASS
        • BEIDOU
        • NAVIC
        • CELLID
        • WLAN
        • MANUAL
        Other values, and combined space separated values are possible too. or null if missing
        Since:
        19387
      • readGpsProcessingMethod

        public static java.lang.String readGpsProcessingMethod​(com.drew.metadata.exif.GpsDirectory dirGps)
        Return the GPS processing method of the given EXIF GPS directory.
        Parameters:
        dirGps - The EXIF GPS directory
        Returns:
        The GPS processing method. Possible values from the EXIF specs are:
        • GPS
        • QZSS
        • GALILEO
        • GLONASS
        • BEIDOU
        • NAVIC
        • CELLID
        • WLAN
        • MANUAL
        Other values, and combined space separated values are possible too. or null if missing or if dirGps is null
        Since:
        19387
      • readCaption

        public static java.lang.String readCaption​(com.drew.metadata.iptc.IptcDirectory dirIptc)
        Returns the caption of the given IPTC directory.
        Parameters:
        dirIptc - The IPTC directory
        Returns:
        The caption entered, or null if missing or if dirIptc is null
        Since:
        15219
      • readHeadline

        public static java.lang.String readHeadline​(com.drew.metadata.iptc.IptcDirectory dirIptc)
        Returns the headline of the given IPTC directory.
        Parameters:
        dirIptc - The IPTC directory
        Returns:
        The headline entered, or null if missing or if dirIptc is null
        Since:
        15219
      • readKeywords

        public static java.util.List<java.lang.String> readKeywords​(com.drew.metadata.iptc.IptcDirectory dirIptc)
        Returns the keywords of the given IPTC directory.
        Parameters:
        dirIptc - The IPTC directory
        Returns:
        The keywords entered, or null if missing or if dirIptc is null
        Since:
        15219
      • readObjectName

        public static java.lang.String readObjectName​(com.drew.metadata.iptc.IptcDirectory dirIptc)
        Returns the object name of the given IPTC directory.
        Parameters:
        dirIptc - The IPTC directory
        Returns:
        The object name entered, or null if missing or if dirIptc is null
        Since:
        15219
      • getRestoreOrientationTransform

        public static java.awt.geom.AffineTransform getRestoreOrientationTransform​(int orientation,
                                                                                   int width,
                                                                                   int height)
        Returns a Transform that fixes the image orientation.

        Only orientation 1, 3, 6 and 8 are supported. Everything else is treated as 1.

        Parameters:
        orientation - the exif-orientation of the image
        width - the original width of the image
        height - the original height of the image
        Returns:
        a transform that rotates the image, so it is upright
      • orientationSwitchesDimensions

        public static boolean orientationSwitchesDimensions​(int orientation)
        Check, if the given orientation switches width and height of the image. E.g. 90 degree rotation

        Only orientation 1, 3, 6 and 8 are supported. Everything else is treated as 1.

        Parameters:
        orientation - the exif-orientation of the image
        Returns:
        true, if it switches width and height
      • orientationNeedsCorrection

        public static boolean orientationNeedsCorrection​(int orientation)
        Check, if the given orientation requires any correction to the image.

        Only orientation 1, 3, 6 and 8 are supported. Everything else is treated as 1.

        Parameters:
        orientation - the exif-orientation of the image
        Returns:
        true, unless the orientation value is 1 or unsupported.