The IPTC Information Interchange Model (IIM) is a set of metadata properties that can be applied to text, images, and other media. The standard also defines a data structure used to store the properties. IPTC IIM was developed by the International Press Telecommunications Council (IPTC) to speed up the international exchange of news, and is now also commonly used by photographers. IPTC IIM metadata can be embedded into a variety of image formats such as JPEG and TIFF.
To access IPTC metadata in a file of any supported format, GroupDocs.Metadata provides the iptc_package property on the root package, which exposes envelope_record and application_record.
fromgroupdocs.metadataimportMetadatadefread_basic_iptc_properties():withMetadata("iptc.jpg")asmetadata:root=metadata.get_root_package()iptc=getattr(root,"iptc_package",None)ifiptcisnotNone:# The envelope record carries transmission-level fieldsifiptc.envelope_recordisnotNone:print(iptc.envelope_record.date_sent)print(iptc.envelope_record.destination)print(iptc.envelope_record.file_format)# The application record carries the editorial fieldsifiptc.application_recordisnotNone:print(iptc.application_record.headline)print(iptc.application_record.by_line)print(iptc.application_record.caption_abstract)print(iptc.application_record.city)print(iptc.application_record.date_created)if__name__=="__main__":read_basic_iptc_properties()
iptc.jpg is the sample file used in this example. Click here to download it.
2019-09-21 00:00:00
None
8
test
None
None
None
2019-09-18 00:00:00
The API provides direct access to the IPTC datasets extracted from a file, including custom ones.
fromgroupdocs.metadataimportMetadatadefread_iptc_datasets():withMetadata("iptc.psd")asmetadata:root=metadata.get_root_package()iptc=getattr(root,"iptc_package",None)ifiptcisnotNone:# to_data_set_list() returns every raw IPTC datasetfordatasetiniptc.to_data_set_list():print(dataset.record_number)# record (e.g. 1=envelope, 2=application)print(dataset.data_set_number)# dataset id within the recordprint(dataset.alternative_name)# human-readable nameprint(dataset.value.raw_value)# underlying valueif__name__=="__main__":read_iptc_datasets()
iptc.psd is the sample file used in this example. Click here to download it.
Update IPTC metadata using the IptcRecordSet properties. Create the records if they are missing.
importuuidfromdatetimeimportdate,datetimefromgroupdocs.metadataimportMetadatafromgroupdocs.metadata.standards.iptcimportIptcApplicationRecord,IptcEnvelopeRecord,IptcRecordSetdefupdate_iptc_properties():withMetadata("input.jpg")asmetadata:root=metadata.get_root_package()# Create the IPTC record set if the image has noneifgetattr(root,"iptc_package",None)isNone:root.iptc_package=IptcRecordSet()# Fill the envelope record (create it first if missing)ifroot.iptc_package.envelope_recordisNone:root.iptc_package.envelope_record=IptcEnvelopeRecord()root.iptc_package.envelope_record.date_sent=datetime.now()root.iptc_package.envelope_record.product_id=str(uuid.uuid4())# Fill the application record (create it first if missing)ifroot.iptc_package.application_recordisNone:root.iptc_package.application_record=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()# Persist the changesmetadata.save("output.jpg")if__name__=="__main__":update_iptc_properties()
input.jpg is the sample file used in this example. Click here to download it.
The API allows adding or updating custom datasets in an IPTC package.
fromgroupdocs.metadataimportMetadatafromgroupdocs.metadata.standards.iptcimport(IptcApplicationRecordDataSet,IptcDataSet,IptcRecordSet,IptcRecordType,)defset_custom_iptc_dataset():withMetadata("iptc.psd")asmetadata:root=metadata.get_root_package()ifgetattr(root,"iptc_package",None)isNone:root.iptc_package=IptcRecordSet()# Add a known property using the DataSet APIroot.iptc_package.set(IptcDataSet(int(IptcRecordType.APPLICATION_RECORD),int(IptcApplicationRecordDataSet.BYLINE_TITLE),"test code sample",))# Add a fully custom IPTC DataSetroot.iptc_package.set(IptcDataSet(255,255,bytes([1,2,3])))metadata.save("output.psd")if__name__=="__main__":set_custom_iptc_dataset()
iptc.psd is the sample file used in this example. Click here to download it.