The IPTC Information Interchange Model (IIM) is a set of metadata properties that can be applied to text, images, and other media types. The standard also defines a complex data structure that is utilized to store the properties. The IPTC IIM was developed by the International Press Telecommunications Council (IPTC) to expedite the international exchange of news among newspapers and news agencies. But nowadays it’s commonly used by amateur and commercial photographers. The standard is supported by many image creation and manipulation programs. IPTC IIM metadata can be embedded into a variety of image formats such as JPEG, TIFF, etc.
Note
For more information on the IPTC IIM standard please refer to https://www.iptc.org/std/IIM/4.2/specification/IIMV4.2.pdf.
Reading basic IPTC IIM properties
To access IPTC metadata in a file of any supported format, GroupDocs.Metadata provides the IIptc.getIptcPackage method. The following are the steps to read IPTC metadata:
In some cases, it’s necessary to read all IPTC datasets (metadata properties) from a file, including custom ones. To achieve this the GroupDocs.Metadata API provides direct access to the IPTC datasets extracted from a file.
The GroupDocs.Metadata API facilitates the user to update IPTC metadata in a convenient way - using the IptcRecordSet class methods. Follow the below steps to update IPTC metadata in a file of any supported format.
try(Metadatametadata=newMetadata(Constants.PsdWithIptc)){IIptcroot=(IIptc)metadata.getRootPackage();// Set the IPTC package if it's missing
if(root.getIptcPackage()==null){root.setIptcPackage(newIptcRecordSet());}// Add a know property using the DataSet API
root.getIptcPackage().set(newIptcDataSet((byte)IptcRecordType.ApplicationRecord,(byte)IptcApplicationRecordDataSet.BylineTitle,"test code sample"));// Add a custom IPTC DataSet
root.getIptcPackage().set(newIptcDataSet((byte)100,(byte)100,newbyte[]{1,2,3}));metadata.save(Constants.OutputPsd);}
Adding repeatable IPTC IIM datasets
According to the IPTC IIM specification some datasets can be added to a record multiple times. The code snippet below demonstrates how to add a repeatable dataset to a record.
try(Metadatametadata=newMetadata(Constants.PsdWithIptc)){IIptcroot=(IIptc)metadata.getRootPackage();// Set the IPTC package if it's missing
if(root.getIptcPackage()==null){root.setIptcPackage(newIptcRecordSet());}root.getIptcPackage().add(newIptcDataSet((byte)IptcRecordType.ApplicationRecord,(byte)IptcApplicationRecordDataSet.Keywords,"keyword 1"));root.getIptcPackage().add(newIptcDataSet((byte)IptcRecordType.ApplicationRecord,(byte)IptcApplicationRecordDataSet.Keywords,"keyword 2"));root.getIptcPackage().add(newIptcDataSet((byte)IptcRecordType.ApplicationRecord,(byte)IptcApplicationRecordDataSet.Keywords,"keyword 3"));metadata.save(Constants.OutputPsd);}// Check the output file
try(Metadatametadata=newMetadata(Constants.OutputPsd)){IIptcroot=(IIptc)metadata.getRootPackage();MetadataPropertykeywordsProperty=root.getIptcPackage().getApplicationRecord().get_Item((byte)IptcApplicationRecordDataSet.Keywords);for(PropertyValuevalue:keywordsProperty.getValue().toArray(PropertyValue.class)){System.out.println(value);}}
Removing IPTC IIM metadata
To remove the IPTC package from a file just pass null to the IIptc.setIptcPackage method as a parameter. The code sample below shows how to remove IPTC metadata from a file.