According to the specification, EXIF (Exchangeable image file format) is a standard that specifies the formats to be used for images, sound and tags in digital still cameras and in other systems handling the image and sound files recorded by digital still cameras. Despite the confusing definition and name of the format, EXIF is just a metadata standard. In fact, it simply defines a way to store metadata properties in a variety of well-known image and audio formats. The EXIF tag structure is borrowed from TIFF files. The specification declares a set of tags intended to store technical details such as the geolocation of the place where a picture was taken, the name of the camera owner, camera settings, etc.
Note
Please refer to the following article to get more information on the standard.
Reading basic EXIF properties
To access EXIF metadata in a file of any supported format, GroupDocs.Metadata provides the IExif.getExifPackage method. The following are the steps to read EXIF metadata:
In some cases, it’s necessary to read all EXIF properties from a file, including custom ones. To achieve this the GroupDocs.Metadata API provides direct access to the EXIF tags extracted from a file.
The GroupDocs.Metadata API also supports reading specific EXIF tags using a method that accepts the tag id as a parameter. Follow below-mentioned steps to read a specific EXIF tag.
The GroupDocs.Metadata API facilitates the user to update EXIF metadata in a convenient way - using the ExifPackage class methods. Follow the below steps to update EXIF metadata in a file of any supported format.
try(Metadatametadata=newMetadata(Constants.InputJpeg)){IExifroot=(IExif)metadata.getRootPackage();// Set the EXIF package if it's missingif(root.getExifPackage()==null){root.setExifPackage(newExifPackage());}root.getExifPackage().setCopyright("Copyright (C) 2011-2020 GroupDocs. All Rights Reserved.");root.getExifPackage().setImageDescription("test image");root.getExifPackage().setSoftware("GroupDocs.Metadata");// ...root.getExifPackage().getExifIfdPackage().setBodySerialNumber("test");root.getExifPackage().getExifIfdPackage().setCameraOwnerName("GroupDocs");root.getExifPackage().getExifIfdPackage().setUserComment("test comment");// ...metadata.save(Constants.OutputJpeg);}
Adding or updating custom EXIF tags
The GroupDocs.Metadata API allows adding or updating custom tags in an EXIF package.
try(Metadatametadata=newMetadata(Constants.TiffWithExif)){IExifroot=(IExif)metadata.getRootPackage();// Set the EXIF package if it's missingif(root.getExifPackage()==null){root.setExifPackage(newExifPackage());}// Add a known propertyroot.getExifPackage().set(newTiffAsciiTag(TiffTagID.Artist,"test artist"));// Add a fully custom property (which is not described in the EXIF specification).// Please note that the chosen ID may intersect with the IDs used by some third party tools.root.getExifPackage().set(newTiffAsciiTag(65523,"custom"));metadata.save(Constants.OutputTiff);}
Here is a full list of tags that can be added to an EXIF package:
To remove the EXIF package from a file just pass null to the IExif.setExifPackage method. The code sample below shows how to remove EXIF metadata from a file.