Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add or Remove Custom XMP Metadata from GIF images in C# using GroupDocs.Metadata for .NET
Add or Remove Custom XMP Metadata from GIF images using C#
1. Add Custom XMP Metadata Package to GIF using C#
2. Read Custom XMP Metadata Package Properties using C#
3. Remove Custom XMP Metadata Package using C#
using (Metadata metadata = new Metadata(@"C:\Files\xmp.gif")) {
IXmp root = (IXmp)metadata.GetRootPackage();
XmpPacketWrapper packet = new XmpPacketWrapper();
XmpPackage custom = new XmpPackage("gd", "https://groupdocs.com");
custom.Set("gd:Copyright", "Copyright (C) 2021 GroupDocs. All Rights Reserved.");
custom.Set("gd:CreationDate", DateTime.Now.ToString());
custom.Set("gd:Company", XmpArray.From(new String[] { "Aspose", "GroupDocs" }, XmpArrayType.Ordered));
packet.AddPackage(custom);
root.XmpPackage = packet;
metadata.Save(@"C:\Files\xmp_output.gif");
}
string file = @"C:\Files\xmp_output.gif";
using (Metadata metadata = new Metadata(file))
{
IXmp root = (IXmp)metadata.GetRootPackage();
if (root.XmpPackage != null)
{
foreach (var package in root.XmpPackage.Packages)
{
Console.WriteLine(package.NamespaceUri);
Console.WriteLine(package.Prefix);
foreach(var keys in package.Keys)
{
var property = package.FindProperties(p => p.Name == keys).FirstOrDefault();
Console.WriteLine(property.Name + " : " + property.Value);
}
}
}
}
using (Metadata metadata = new Metadata(@"C:\Files\xmp_output.gif"))
{
IXmp root = (IXmp)metadata.GetRootPackage();
root.XmpPackage = null;
metadata.Save(@"C:\Files\xmp_output_Removed.gif");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment