Write Xmp metadata back to file

931 views Asked by At

I'm using an image processing API which resizes and reformats an image from jpg to png. During this process the image loses the metadata.

Is there a way to write the metadata back to file. I can get the xmp metadata from the original but now I need to write it back to the new file.

This is my code so far using the metadata-extractor framework for .Net

public static void ReadXmpData(string fileLocation)
    {
        var xmpDirectory = ImageMetadataReader.ReadMetadata(fileLocation).OfType<XmpDirectory>().FirstOrDefault();

        foreach (var property in xmpDirectory.XmpMeta.Properties)
        {
            Console.WriteLine($"Path:\t{(property.Path != null ? property.Path.Trim() : property.Path)}\n" +
                                $"Namespace:\t{(property.Namespace != null ? property.Namespace.Trim() : property.Namespace)}\n" +
                                $"Value:\t{(property.Value != null ? property.Value.Trim() : property.Value)} \n\n\n");
        }
    }

Any help or guidance would be appreciated.

Edit: I am aware that metadata-extractor does not yet support the writing of xmp data

1

There are 1 answers

0
Dan On

Use ImageMagick.net which will do image transformations without destroying the exif or xmp metadata. I use this for major film/tv studio images and works great.