I would need to take an existing jpg file and modify the title, the description and the keywords in its IPTC entries. There are several topics here on this but all either without answer or with partial answers. I already know how to read the IPTC informations, but would need to edit them. Could somebody shed some light on this much researched and less known topic?
what i have is:
NSString: title
NSString: description
NSArray: keywords
NSString: path to the file
I would like to take an existing image with existing IPTC data and replace the existing entries with these, but preserve all other IPTC entries such as location, date and so on. All I know so far is that i need to use CGImageDestination.
Thanks
you should use XMP Toolkit SDK, you can find detailed information at adobe SDK page implementing is little bit tricky but once you add static libraries to your project you can read and write XMP information, it covers IPTC namespace as well upon others namespaces as like dublin-core etc.
After you add libraries to project code like this.
writing is pretty much same.
you can find all namespace constants in documentation as like kXMP_NS_DC XMP NameSpace DublinCore etc.
Apple's Image/IO suppose to cover all but for instance you can read byline entry from IPTC with Image/IO however you can't write it.
Image/IO Reference
CGImageProperties Reference
You should first read the metadata from the file:
In the code above,
url
is the URL of your image file.props
will have all the metadata of the image at the destination URL.Then, you copy that data to a new mutable, empty data source:
Finally, let's assume you've modified the metadata in a new
NSDictionary
instance (calledmodifiedMetadata
in this example):This would write the metadata to the destination image. At least in my case, it works perfectly.
To save the image data to an actual file, you can write the data regularly, e.g: