2

I am writing some XMP metadata using a photoshop .jsx script using :

var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData); XMPMeta.registerNamespace(nameSpace, nsPrefix);

and then adding some data to this new namespace. I am able to view it in Photoshop by checking under File -> FileInfo. My question is how can I access this data using the metadata extractor library in my c# project ? When I use the following code I do not see the new metadata I added inside any of the directories:

FileStream OriginalFile = new FileStream("C:\\Users\\av\\Desktop\\test.tif", FileMode.Open, FileAccess.Read, FileShare.Read); IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(OriginalFile);

Edit: I am able to loop through all the properties but when I try to do

var xmpDirectory = ImageMetadataReader.ReadMetadata("path/test.tif").OfType<XmpDirectory>().FirstOrDefault(); xmpDirectory.XmpMeta.GetProperty("http://ns.adobe.com/xap/1.0/mm/xmpMM:DerivedForm/", "stRef:documentID")

I get an exception. The property is present when I look at it through Photoshop.

xmp data in photoshop

AkVenu
  • 25
  • 5

1 Answers1

2

XMP data is stored in the XmpDirectory. Access it via:

var xmpDirectory = ImageMetadataReader.ReadMetadata("path\test.tif")
    .OfType<XmpDirectory>().FirstOrDefault();

Note however that XMP data in metadata-extractor does not follow the standard tag/value format of other directories. Instead, you should access the XmpMeta property of the directory in order to inspect that data.

You can then write code resembling:

foreach (var property in xmpDirectory.XmpMeta.Properties)
    Console.WriteLine($"Path={property.Path} Namespace={property.Namespace} " +
                       "Value={property.Value}");

Some more discussion here and more information about the XMP library here.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • where is XmpDirectory ? It does not seem to be a part of XmpCore or MetadataExtractor. – AkVenu Oct 24 '16 at 21:35
  • Sorry my bad. I found it. – AkVenu Oct 24 '16 at 21:36
  • @DrewNoakes: Can't find those data: `FirstOrDefault` returns null on all my images (Canon CR2 from various cameras). Still data exists, I see them in Photoshop. Any clue? – PPC Dec 02 '16 at 09:55
  • @PPC the data is probably not stored as XMP. If you're sure it is, please open an issue and attach a sample image. – Drew Noakes Dec 02 '16 at 23:18