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. Nowadays it’s also commonly used by photographers. IPTC IIM metadata can be embedded into a variety of image formats such as JPEG, TIFF, etc.
To access IPTC metadata in a file of any supported format, GroupDocs.Metadata provides the IIptc.iptc_package property. 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 properties. Follow the below steps to update IPTC metadata in a file of any supported format.
defrun():withgm.Metadata(constants.input_jpeg)asmetadata:root=metadata.get_root_package()# Set the IPTC package if it's missingifnothasattr(root,"iptc_package")orroot.iptc_packageisNone:root.iptc_package=gm.standards.iptc.IptcRecordSet()ifroot.iptc_package.envelope_recordisNone:root.iptc_package.envelope_record=gm.standards.iptc.IptcEnvelopeRecord()root.iptc_package.envelope_record.date_sent=datetime.now()root.iptc_package.envelope_record.product_id=str(uuid.uuid4())# ...ifroot.iptc_package.application_recordisNone:root.iptc_package.application_record=gm.standards.iptc.IptcApplicationRecord()root.iptc_package.application_record.by_line="GroupDocs"root.iptc_package.application_record.headline="test"root.iptc_package.application_record.by_line_title="code sample"root.iptc_package.application_record.release_date=date.today()# ...metadata.save(constants.output_jpeg)
Adding or updating custom IPTC IIM datasets
The GroupDocs.Metadata API allows adding or updating custom datasets in an IPTC package.
defrun():withgm.Metadata(constants.psd_with_iptc)asmetadata:root=metadata.get_root_package()ifnothasattr(root,"iptc_package")orroot.iptc_packageisNone:root.iptc_package=gm.standards.iptc.IptcRecordSet()# Add a known property using the DataSet APIroot.iptc_package.set(gm.standards.iptc.IptcDataSet(int(gm.standards.iptc.IptcRecordType.APPLICATION_RECORD),int(gm.standards.iptc.IptcApplicationRecordDataSet.BYLINE_TITLE),"test code sample"))# Add a custom IPTC DataSetroot.iptc_package.set(gm.standards.iptc.IptcDataSet(255,255,bytes([1,2,3])))metadata.save(constants.output_psd)
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.
defrun():withgm.Metadata(constants.psd_with_iptc)asmetadata:root=metadata.get_root_package()ifnothasattr(root,"iptc_package")orroot.iptc_packageisNone:root.iptc_package=gm.standards.iptc.IptcRecordSet()root.iptc_package.add(gm.standards.iptc.IptcDataSet(int(gm.standards.iptc.IptcRecordType.APPLICATION_RECORD),int(gm.standards.iptc.IptcApplicationRecordDataSet.KEYWORDS),"keyword 1"))root.iptc_package.add(gm.standards.iptc.IptcDataSet(int(gm.standards.iptc.IptcRecordType.APPLICATION_RECORD),int(gm.standards.iptc.IptcApplicationRecordDataSet.KEYWORDS),"keyword 2"))root.iptc_package.add(gm.standards.iptc.IptcDataSet(int(gm.standards.iptc.IptcRecordType.APPLICATION_RECORD),int(gm.standards.iptc.IptcApplicationRecordDataSet.KEYWORDS),"keyword 3"))metadata.save(constants.output_psd)# Check the output filewithgm.Metadata(constants.output_psd)asmetadata:root=metadata.get_root_package()keywords_property=root.iptc_package.application_record[int(gm.standards.iptc.IptcApplicationRecordDataSet.KEYWORDS)]forvalueinkeywords_property.value.to_array(gm.common.PropertyValue):print(value)
Removing IPTC IIM metadata
To remove the IPTC package from a file just assign None to the IIptc.iptc_package property. The code sample below shows how to remove IPTC metadata from a file.
Along with full featured Python via .NET library we provide simple, but powerful free Apps.
You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.