Add or Remove Custom XMP Metadata from GIF using C#

The Extensible Metadata Platform (XMP) metadata is encoded as XML-formatted text. The defined XMP data model can be used to store any set of metadata properties in the form of name/value pair. You can add a custom XMP metadata package to your images programmatically. In this article, you will learn how to add or remove custom XMP metadata from GIF using C#.

The following topics are discussed/covered in this article:

C# API for Adding or Removing XMP Metadata

I will be using GroupDocs.Metadata for .NET API for adding or removing custom XMP metadata package. It allows you to add, edit, retrieve, and remove metadata properties from documents and image file formats. The API works with the most notable metadata standards such as built-in, XMP, EXIF, IPTC, Image Resource Blocks, ID3, and custom metadata properties. It can be used to develop applications in any development environment that targets the .NET platform.

You can either download the DLL of the API or install it using the NuGet.

Install-Package GroupDocs.Metadata

Add Custom XMP Metadata Package to GIF using C#

You can easily create and add a fully custom XMP package containing user-defined properties by following the simple steps mentioned below:

The following code sample shows how to create and add a custom XMP metadata package to GIF image using C#.

The above code sample shall add the XMP metadata package to input image. The ExifTool read the following metadata from the generated output GIF image.

Add XMP Metadata Package to GIF using C#

Add XMP Metadata Package to GIF using C#

The IXMP interface exposes XmpPackage{.broken_link} property to gets or set the XMP metadata package.

The Metadata class provides GetRootPackage method to get the root package that provides access to all metadata properties extracted from the file.

The XmpPackage class provides various properties to define the package such as Prefix, NamespaceUri, and Keys. This class also provides Set methods to set name/ value for user defined metadata properties.

The XmpPacketWrapper class contains serialized XMP package. The AddPackage method of this class allows to add the defined custom package.

You can find more details about “Working with XMP Metadata” in the documentation.

Read Custom XMP Package Metadata Properties using C#

You can easily read all the custom XMP package user-defined properties by following the simple steps mentioned below:

The following code sample shows how to read all the properties defined in the custom XMP package using C#.

The above code sample shall produce the following output:

https://groupdocs.com
gd
gd:Copyright: Copyright (C) 2021 GroupDocs. All Rights Reserved.
gd:CreationDate: 04/05/2021 2:26:17 am
gd:Company: <rdf:Seq><rdf:li>Aspose</rdf:li><rdf:li>GroupDocs</rdf:li></rdf:Seq>

The FindProperties method of the XmpPackage class recursively searches and finds the metadata properties satisfying the specified predicate.

Remove Custom XMP Package using C#

You can remove XMP package from GIF images by following the simple steps mentioned below:

The following code sample shows how to remove XMP metadata package from GIF image using C#.

The above code sample shall remove the XMP metadata package from input image. The ExifTool read the following metadata from the generated output GIF image.

Remove XMP Metadata Package from GIF using C#

Remove XMP Metadata Package from GIF using C#

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to add or remove custom XMP package metadata from GIF images using C#. You also learned how to read XMP package properties using C#. Moreover, you can learn about GroupDocs.Metadata for .NET API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also