ASP code to write EXIF metadata to JPEGs and TIFFs with csImageFile

The ASP component csImageFile can be used to read and write EXIF data that is stored in JPEG and TIFF images. This data is usually written at the time that the image is created, usually by the camera or scanner. Most of the EXIF attributes should not be edited because they are related to the camera settings or conditions at the time of creating the image, but some attributes, such as the description and copyright information, can be edited separately. The code fragments on this page form an extension to the csImageFile instructions.

The ExifSetAttribute method

csImageFile does not store a separate property for each EXIF attribute. Instead it uses a single method for setting all the attributes, which must be called with the attribute name as one parameter and the new value in string form as the other parameter. The following code fragment shows how to set four EXIF attributes. It assumes that the csImageFile object has been created with a name Image and a JPEG or TIFF image has been loaded.

Image.ExifSetAttribute "ImageDescription", "Description or title of the image."
Image.ExifSetAttribute "Artist", "The author of the image."
Image.ExifSetAttribute "Copyright", "A copyright notice"
Image.ExifSetAttribute "DateTime", Image.ExifDateToString(Now)

The first parameter of ExifSetAttribute is the name of the EXIF tag which must be a recognised tag name, although it is not case sensitive. The second parameter is the new value, and this must be a string even if the attribute that is stored is not a string. To set the DateTime attribute the current date/time is passed to the ExifDateToString method where it is converted from an ActiveX date/time to the correct format of string.

Checking the data has been written

The ExifSetAttribute method has a Boolean return value which is true when the value was set correctly but false if it was not set. The method does not return an error. If the tag name is not recognised or if the data is in an incorrect format, the return value will be false.

For example:

Response.Write Image.ExifSetAttribute("ImageDescription", "A new description")

Note that the ExifSetAttribute parameters are enclosed in brackets when the return value is used.

EXIF attributes which might be edited after creating the image

We do not provide a list of the available EXIF attributes, as there are over 100 different attributes. The following tags are the ones that are most likely to be edited. The first are all strings.

ImageDescription - Image title

Software - Software used

Artist - Person who created the image

Copyright - Copyright holder

The next are date/time values.

DateTime - File change date and time

DateTimeOriginal - Date and time of the original data generation

DateTimeDigitized - Date and time of digital data generation

Click here for more on reading EXIF attributes.