Magick.NET is unable to read/write extended XMP data
I've hit a problem with XMP data where the data is stored as extended XMP segments. It looks like Image Magick/Magick.NET don't read or write extended XMP data correctly and this is preventing me from reading information from the XMP profile.
I've had a read of the XMP specification (link at the bottom of this). When XMP data in an image extends beyond 64Kb, the profile is supposed to be split in to one standard segment and one (or more) extended segments, each under 64Kb in size. Each segment is variable length, and the application that writes the data is responsible for the way in which the XMP data is split across different segments.
The specification says that extended segments should be written as follow: "Each chunk is written into the JPEG file within a separate APP1 marker segment. Each ExtendedXMP marker segment contains:
- A null-terminated signature string of "http://ns.adobe.com/xmp/extension/".
- A 128-bit GUID stored as a 32-byte ASCII hex string, capital A-F, no null termination. The GUID is a 128-bit
- MD5 digest of the full ExtendedXMP serialization.
- The full length of the ExtendedXMP serialization as a 32-bit unsigned integer
- The offset of this portion as a 32-bit unsigned integer.
- The portion of the ExtendedXMP"
See XMP storage specification, section 1.1.3.1 (https://wwwimages2.adobe.com/content/dam/acom/en/devnet/xmp/pdfs/XMP%20SDK%20Release%20cc-2016-08/XMPSpecificationPart3.pdf)
Would it be possible to first determine if we do not read the information correctly? And if that is the problem could you add a sample image so I can also reproduce it?

Sorry, of course. The attached image has an XMP profile which contains extended data segments. Calling .ToXDocument or ToIXPathNavigable throw an exception (Data at the root level is invalid.). I can get the profile as a byte array, and if I use System.Encoding to convert it to a string, it looks like it does include everything. But if I then try to add the profile back to the image using .AddProfile() the image XMP isn't readable.
So I could work around the issue, but it would be useful if I could save the profile.
PS: Sorry, to anonymize the image I made it white, but that doesn't stand out on the page!
@Brubning No problem 👍 Next time it better be magenta though 😛
I will try to take a look at this on Friday.
It looks like I need to parse the data of the XMP profile and restore the original document. Will need to read the documentation and figure out how to do this. Feel free to also help me out with this one 👍
The spec says that if the XMP profile > 64Kb, it will be split into multiple <?segment?> blocks, separated with an APP1 declaration. If I use XmpProfile.ToByteArray() and then convert to a string, I can see the separate blocks. So I guess it's just a case of parsing that into distinct XMP profile segments.
Happy to have a look, but can't push local changes to initiate a pull request at the mo.