我有 50,000 多张图像的元数据,格式包括 .jpeg、.tif、.psd、.pdf 等。我正在尝试使用 GraphicsMagick.NET 将图像的元数据嵌入到其 IPTC 字段中。将 IPTC 配置文件添加到图像并保存图像后,它似乎正在工作——GraphicsMagick 可以检索我刚刚为图像保存的 IPTC 配置文件。
但是,当我查看图像的属性时,我看不到任何更改。
我做错了吗?GraphicsMagick 不写入标准 IPTC 字段吗?
这是一个简单的控制台应用程序来演示我的问题:
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
}
}
}