I have meta data for 50,000+ images in formats including .jpeg, .tif, .psd, .pdf, etc. I am attempting to embed the meta data for an image into its IPTC fields using GraphicsMagick.NET. After adding an IPTC profile to the image and saving the image, it appears to be working -- GraphicsMagick can retrieve the IPTC profile I just saved for the image.
When I view the image's properties, however, I am unable to see any of my changes.
Am I doing this incorrectly? Does GraphicsMagick not write to the standard IPTC fields?
Here's a simple console application to demonstrate my issue:
class Program
{
static void Main(string[] args)
{
EmbedIptcMetaData();
}
private static void EmbedIptcMetaData()
{
// Picture of a cake found here: https://static.pexels.com/photos/353347/pexels-photo-353347.jpeg
// Labeled for reuse with modification
// Saved to desktop
string desktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
string originalFilePath = System.IO.Path.Combine(desktopPath, "pexels-photo-353347.jpeg");
string modifiedFilePath = System.IO.Path.Combine(desktopPath, "pexels-photo-353347-modified.jpeg");
// NuGet package: GraphicsMagick.NET-Q8-AnyCPU
using (GraphicsMagick.MagickImage image = new GraphicsMagick.MagickImage(originalFilePath))
{
// Read the initial IPTC profile of the image
GraphicsMagick.IptcProfile initialProfile = image.GetIptcProfile(); // initialProfile has the image author, Ana Paula Silva
// Create a new IPTC profile
GraphicsMagick.IptcProfile newProfile = new GraphicsMagick.IptcProfile();
newProfile.SetValue(GraphicsMagick.IptcTag.Keyword, "cake,wedding,photography");
// Add the new IPTC profile
image.AddProfile(newProfile);
// Save the image
image.Write(modifiedFilePath); // I expect the IPTC profile to now only have a value for the caption field
}
using (GraphicsMagick.MagickImage modifiedImage = new GraphicsMagick.MagickImage(modifiedFilePath))
{
// Read the modified image's IPTC profile
GraphicsMagick.IptcProfile profile = modifiedImage.GetIptcProfile(); // profile == newProfile from above
}
}
}
After much additional research, it appears that GraphicsMagick was actually writing to XMP fields on the image. The documentation is sparse, and I wasn't able to figure out a way to write keywords to any index other than 0.
Ultimately I switched to using Atalasoft DotImage.