Detailed documentation

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.
tell application "iMagine Photo"
set thisFile to choose file with prompt "Choose an image file containing exif data:" without invisibles
set thisImporter to import graphic thisFile
set exifInfo to the exif data of thisImporter
close thisImporter
exifInfo
end tell
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.
property unicodeType : 1
property floatType : 2
property intType : 3
property float3Type : 4
property gExifList : missing value
on InitExifList()
using terms from application "iMagine Photo"
set gExifList to {
{exif type:info, exifData:unicodeType, titleText:"Headline"},
{exif type:exif make, exifData:unicodeType, titleText:"Maker"},
{exif type:exif model, exifData:unicodeType, titleText:"Model"},
{exif type:software, exifData:unicodeType, titleText:"Software"},
{exif type:exif creation date, exifData:unicodeType, titleText:"File Creation Date"},
{exif type:orientation, exifData:unicodeType, titleText:"Orientation"},
{exif type:exposure time in seconds, exifData:floatType, titleText:"Exposure Time (sec)"},
{exif type:aperture fNum, exifData:floatType, titleText:"Aperture fNum"},
{exif type:exposure program, exifData:unicodeType, titleText:"Exposure Program"},
{exif type:ISO film speed, exifData:intType, titleText:"ISO Film Speed"},
{exif type:capture date, exifData:unicodeType, titleText:"Capture Date"},
{exif type:exposure bias EV, exifData:floatType, titleText:"Exposure Bias"},
{exif type:metering mode, exifData:unicodeType, titleText:"Metering Mode"},
{exif type:light source, exifData:unicodeType, titleText:"Light Source"},
{exif type:flash, exifData:unicodeType, titleText:"Flash"},
{exif type:focal length mm, exifData:floatType, titleText:"Focal Length"},
{exif type:capture width in pixels, exifData:intType, titleText:"Capture Width (pixels)"},
{exif type:capture height in pixels, exifData:intType, titleText:"Capture Height (pixels)"},
{exif type:copyright, exifData:unicodeType, titleText:"Copyright"},
{exif type:artist, exifData:unicodeType, titleText:"Artist"},
{exif type:gps latitude ref, exifData:unicodeType, titleText:"Latitude Reference"},
{exif type:gps longitude ref, exifData:unicodeType, titleText:"Longitude Reference"},
{exif type:gps latitude, exifData:float3Type, titleText:"Latitude"},
{exif type:gps longitude, exifData:float3Type, titleText:"Longitude"},
{exif type:gps altitude, exifData:floatType, titleText:"Altitude (m)"},
{exif type:gps altitude ref, exifData:intType, titleText:"Altitude Ref"},
{exif type:comment, exifData:unicodeType, titleText:"Comment"}
}
end using terms from
end InitExifList
The above code is used in Script 1 to create a tab delimited text file that can be opened in most spreadsheet applications. The script allows you to choose which meta data you want, the folder that contains the image files and the location and name of the spreadsheet file to be created. The script is currently configured to process files and files in subfolders of the selected folder. It is simple to modify the script to process files only in the selected folder.
Scripts 2, 3 and 4 all require MySQL to be installed on the system the script is running on.
Script 2 will allow you to optionally create a MySQL database, and to create a MySQL table. When creating the table you will be able to choose from a list of meta data properties that you want to be the fields of your database. The script automatically selects an appropriate MySQL type for each field.
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.
tell application "iMagine Photo"
set thisFile to choose file with prompt "Image file with exif data: "
set savedFile to choose file name default name "NewImageFile.jpg"
set copyrightText to text returned of (display dialog "Enter the copyright text: " default answer "Copyright Yarra Valley Software, http://www.yvs.eu.com, Oxford UK 2004")
set artistText to text returned of (display dialog "Photographers name: " default answer "Kevin Meaney")
set iMageInfo to text returned of (display dialog "Information about the image: " default answer "On holidays in Austria")
set thisImporter to import graphic thisFile
tell thisImporter to make exporter with properties {export file type:"JPEG"}
set the export file location of thisImporter to savedFile
set exifData to the exif data of thisImporter
set the export exif data of thisImporter to exifData
set the export exif data of thisImporter to {{exif type:copyright, exif unicode:copyrightText}, {exif type:artist, exif unicode:artistText}, {exif type:info, exif unicode:iMageInfo}}
export thisImporter
close thisImporter
set thisImporter2 to import graphic savedFile
set exifData2 to the exif data of thisImporter2
close thisImporter2
end tell
exifData2
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:
set the export exif data of thisImporter to exifData
replacing it with:
set the export exif user data of thisImporter to exifData
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.
set the export exif data of objectWithExporter to {{exif type:gps longitude ref, exif unicode:"E"}, {exif type:gps latitude ref, exif unicode:"N"}, {exif type:gps latitude, exif float:{35.0, 36.0, 57.669998168945}, exif unicode:{"3500000/100000", "3600000/100000", "5767000/100000"}}, {exif type:gps longitude, exif float:{139.0, 41.0, 50.340000152588}, exif unicode:{"1390000/10000", "4100000/100000", "5034000/100000"}}, {exif type:gps altitude ref, exif unicode:"Sea level", exif int:0}, {exif type:gps altitude, exif float:78.000007629395, exif text:"7800001/100000"}}
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 http://homepage.mac.com/jonn8/as/
keywords: AppleScript, Apple Script, exif jpeg, jpg, image, images, Macintosh, Quicktime, tiff, tif.