Reading and Writing Exif metadata

iMagine Photo reads and writes a comprehensive range of meta data from image files. This includes many exif types and image properties like resolution and color depth etc.

iMagine Photo uses Quicktime to read and write image meta data. When writing exif information Quicktime overwrites a small number of the meta data types with its own data, the meta data types that will be overwritten are: comment, software, host os, and creation date. Note that there is a another exif date entry that stores the capture date which Quicktime does not overwrite, it is therefore possible to retain the capture date information when modifying the exif data. You can see the list of exif types that you can write using iMagine Photo below.

There are a number of extra exif types that iMagine Photo can read but not set, these types all return textual information. If your image files contain exif information that are not listed in iMagine Photo's AppleScript dictionary I would request the metadata and see if iMagine Photo returns the required type.

The following AppleScript displays the exif data in the results log of the Script Editor window. Panther users click here to open this script in a new Script Editor window.

iMagine Photo returns the exif information in various formats depending on the exif type. Every exif property is returned as text (exif unicode), however some properties are also returned as integers (exif int) or floating point numbers (exif float). Two exif properties "gps latitude" and "gps longitude" are exceptions as they return a list of 3 floating point numbers (exif float) and three text entries (exif unicode) the first representing degrees, the second minutes and the third representing seconds. iMagine Photo can read and write gps information.

The following code creates a list of records that describe most of the exif types that iMagine Photo recognizes. The information in this list describes the most appropriate type for the exif data to be returned. It also lists possible titles for table columns of the exif types. I use this code in a script that creates a text file of data that can be interpreted by most spreadsheet applications.

Panther users can display the following code in a new Script Editor window by clicking here. Running this code by itself does not do anything. Cutting and pasting the following code into a Script Editor will require some editing to get it to compile as the line breaks in the list is not valid AppleScript.

Scripts 2, 3 and 4 all require MySQL to be installed on the system the script is running on.

Script 3 adds image file meta data to a MySQL database. When the script is run, it asks the user for the folder containing the image files and the necessary information to specify the MySQL database and table that the meta data will be added to. Script 4 is a droplet version of Script 3. The MySQL scripts use the above code or a modified version which contains the MySQL type information. It is simple to modify the scripts to process files only in the selected folder.

The scripts below which create new image files, all assume that you want to create JPEG files. If you wish to create TIFF files then where you see: export file type:"JPEG" replace that with export file type:"TIFF". Only TIFF and JPEG store exif data.

The following script asks the user for a file to get the exif data from, a new file name and location where the new image file will be created, and the copyright, artist name, and some info about the image. The script will then create a new image file containing the exif types from the original file that iMagine Photo can interpret, and add the copyright, artist name, and info to the exif data of the image file. The script will display the exif contents of the new image file in the results log. Panther users can open the script in a new Script Editor window by clicking here.

There are some exif types that iMagine Photo cannot interpret but Quicktime knows about like maker note. This information can usually only be displayed using the manufacturers software. iMagine Photo provides a mechanism of copying this information to the new image file. Instead of the line of code in the script above:

replacing it with:

will copy all the exif user data that Quicktime will allow you to. When setting individual bits of the exif user data you should always do that after copying the original exif data to the new file. Copying this extra information may not always be desireable as it can be quite large. For example, it adds over 1000 bytes to my image files for my digital camera

Script 5 creates new files with the exif information in a file with a selected subset of the original exif information plus adding the artist, copyright and info exif types. This script doesn't recompress the picture data. For more information on securing your image files go to the Watermark/Security page.

To write GPS position information, it is necessary to set degrees, minutes and seconds for both longitude and latitude, it is also necessary to set longitude and latitude reference plus altitude reference (nearly always 0 to indicate sea level) and the altitude.

The following example shows how to set the gps information for a graphic exporter attached to a graphic/window document or a graphic importer. The accuracy is around 20 metres when the seconds is specified to 2 places after the decimal point.

iMagine Photo gives priority to the float and int types for setting the exif information, over unicode.

The ability to open scripts in a new Script Editor window is provided by an application called "Convert Script to Markup Code" and can be obtained from

keywords: AppleScript, Apple Script, exif jpeg, jpg, image, images, Macintosh, Quicktime, tiff, tif.