Reading image EXIF data

June 5, 2009 / Filed under: EXIF, Images, GPS, Metadata

Every image taken with a digital camera has information stored as part of the image file itself, such as camera make/model, orientation, date/time the photo was taken, etc.

You can view and extract this information with the right tools. One unique application might be to extract the latitude and longitude of the image file, and place it on a map which displays the location of each photo you shoot.

Viewing image EXIF data

To view image EXIF data, you can manually open each image in a program that can read the EXIF data for you. For example, Adobe Photoshop and Graphic Converter both let you view the EXIF data:

Screenshot of Adobe Photoshop window

Screenshot of GraphicConverter window

You can also obtain the EXIF data programmatically. Here is a good example of how to use PHP to obtain the EXIF data for an image file:

function get_exif_data($file) {
  $exif = exif_read_data($file, 0, true);
  return $exif;
}

$image_file = '/path/to/image.jpg';
$image_exif = get_exif_data($image_file);

echo "

Image EXIF data

"; echo "
";
print_r($image_exif);
echo "
";

The example code above would produce something like this:


Array
(
    [FILE] => Array
        (
            [FileName] => image.jpg
            [FileDateTime] => 1244222861
            [FileSize] => 388321
            [FileType] => 2
            [MimeType] => image/jpeg
            [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS
        )

    [COMPUTED] => Array
        (
            [html] => width="1600" height="1200"
            [Height] => 1200
            [Width] => 1600
            [IsColor] => 1
            [ByteOrderMotorola] => 1
            [ApertureFNumber] => f/2.8
            [Thumbnail.FileType] => 2
            [Thumbnail.MimeType] => image/jpeg
        )

    [IFD0] => Array
        (
            [Make] => Apple
            [Model] => iPhone
            [Orientation] => 1
            [XResolution] => 72/1
            [YResolution] => 72/1
            [ResolutionUnit] => 2
            [DateTime] => 2009:06:03 11:31:25
            [Exif_IFD_Pointer] => 171
            [GPS_IFD_Pointer] => 317
        )

    [THUMBNAIL] => Array
        (
            [Compression] => 6
            [Orientation] => 1
            [XResolution] => 72/1
            [YResolution] => 72/1
            [ResolutionUnit] => 2
            [JPEGInterchangeFormat] => 561
            [JPEGInterchangeFormatLength] => 6495
        )

    [EXIF] => Array
        (
            [FNumber] => 14/5
            [DateTimeOriginal] => 2009:06:03 11:31:25
            [DateTimeDigitized] => 2009:06:03 11:31:25
            [ColorSpace] => 1
            [ExifImageWidth] => 1600
            [ExifImageLength] => 1200
            [UndefinedTag:0xA500] => 11/5
        )

    [GPS] => Array
        (
            [GPSLatitudeRef] => N
            [GPSLatitude] => Array
                (
                    [0] => 19/1
                    [1] => 2977/100
                    [2] => 0/1
                )

            [GPSLongitudeRef] => W
            [GPSLongitude] => Array
                (
                    [0] => 155/1
                    [1] => 5713/100
                    [2] => 0/1
                )

            [GPSTimeStamp] => Array
                (
                    [0] => 11/1
                    [1] => 31/1
                    [2] => 2279/100
                )

        )

)

Please note: depending on the digital camera model, the above array items may differ slightly.

With this array of data, you can do just about anything with your image from here.

Comments/Mentions

# Andy at 6/26/2009 3:42 pm cst

For Ruby programmers out there, check out the exifr gem.

# Hila at 10/4/2009 12:50 am cst

Can the EXIF data be modified programmatically, or is it some sort of exclusive control that only camera/device makers have?

In other words, can one write code that would embed additional information about the photo into the EXIF data?