EXIF removal for an image is not working with GroupDocs.Metadata

Hi,
We are using GroupDocs.Metadata 21.8.0. and the .Net version is 4.7.2. We tried removing EXIF data using this approach but the resultant image still contains the EXIF data. Can you tell us if it is a known issue or any additional thing we need to implement?

this is the code we have added.

            string file_extension = Path.GetExtension(file.Key);
            MemoryStream output = new MemoryStream(file.Value.StreamToByteArray());
            if (file_extension != ".jpg" && file_extension != ".jpeg")
            {
                return output;
            }
            try
            {
                using (Metadata metadata = new Metadata(file.Value))
                {
                    IExif root = metadata.GetRootPackage() as IExif;
                    if (root != null)
                    {
                        root.ExifPackage = null;
                        output.Flush();  // tried both with/without this
                        output.SetLength(0); // tried both with/without this
                        metadata.Save(output);
                    }
                }
                return output;
            }

Thanks,
Shrey

@shrey
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): METADATANET-4016

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi,
any update on this?

@shrey

This ticket is still under investigation . We’ll notify you in case of any update.

@shrey

Please use two different streams, input and output. Below is a code example:

// Open an input stream for reading from the input file.
FileStream inputStream = new FileStream(inputPath, FileMode.Open);

// Check the file extension; if it's not a JPEG, exit the process.
if (file_extension != ".jpg" && file_extension != ".jpeg")
{
    return;
}

// Create or open an output stream for writing to the output file.
FileStream outputStream = new FileStream(outputPath, FileMode.OpenOrCreate);

// Create a Metadata object to work with the input stream's metadata.
using (Metadata metadata = new Metadata(inputStream))
{
    // Get the root package of metadata as an Exif package.
    IExif exifPackage = metadata.GetRootPackage() as IExif;

    // If the Exif package is found, remove it from the metadata.
    if (exifPackage != null)
    {
        exifPackage.ExifPackage = null;

        // Save the modified metadata to the output stream.
        metadata.Save(outputStream);
    }
}

Let us know if issue persists.

Hi @atir.tahir,
I don’t think it is an output stream issue. It was different only in the first example. Still, I tried to simplify the example and tried to directly save the file but the metadata doesn’t get removed. attaching the image of the resultant metadata.

        MemoryStream output = new MemoryStream();
        try
        {
            using (Metadata metadata = new Metadata(file.Value))
            {
                IExif root = metadata.GetRootPackage() as IExif;
                if (root != null)
                {
                   // root.ExifPackage.Clear();
                  //  root.ExifPackage.GpsPackage.Clear();
                    root.ExifPackage = null;
                    string file_path = @"C:\Users\dv-user\Desktop";
                    metadata.Save(Path.Combine(file_path, file.Key));
                }
                else
                {
                    //return file.Value;
                }
            }
           // return output;
        }
        catch(Exception ex)
        {
            // dispose the output stream
            output.Dispose();
           // return file.Value;
        }

image.png (62.6 KB)

1 Like

@shrey

We’ll continue investigation and let you know in case of any progress update.

@shrey

Could you please share the problematic file as well? Also specify the development environment (e.g. Operating system name and version).

Hi,
attaching the image.
Development env: Windows 11 Home, Version 22H2

Metadata_test_file_-_includes_data_in_IIM,_XMP,_and_Exif.jpg (81.7 KB)

@shrey
Thanks for the details. We’ll continue our investigation.

@shrey

The attached file does not have EXIF content. For other files the code that we provided earlier works correctly. The content is deleted.
Please try again using this code example.zip (608 Bytes) and this input.jpg (876.2 KB) file.

Hi,
looks like this editor itself removes the EXIF. since the same file present in my system has the metadata. also, the file suggested by you also doesn’t have any metadata. image.png (27.7 KB)

attaching the file again in a zip for you to check. Metadata_test_file_-_includes_data_in_IIM,_XMP,_and_Exif.zip (94.9 KB)

1 Like

@shrey

Thank you for providing us with your information. We will proceed with the investigation and keep you informed in case of any updates.

@shrey

The file you shared has an EXIF section, we tested it using the code example provided earlier, the section is deleted correctly.
Could you please share a short video explaining steps to reproduce the issue?