Skip to content

Exif data not persisted after loading #1764

Closed
@etihwddot

Description

@etihwddot

Magick.NET version

14.2

Environment (Operating system, version and so on)

Windows

Description

When loading some images with MagickImage and writing them to a stream or saving ToByteArray the loaded exif metadata is no longer written to the output. This causes some things like orientation information to be lost.

This appears to be a regression from earlier versions of Magick.NET. Specifically, we were previously using 13.4 before upgrading and seeing this new behavior. It seems likely that the image is corrupt in some way (at the very least looks like it doesn't have the EOI marker) but it was great that MagickImage handled these corrupt images from our users better in the previous version.

We have a workaround for orientation by calling AutoOrient before persisting to a byte array but I don't know if there is other important metadata that could be lost in this process.

Steps to Reproduce

The following output samples are from using the image attached to this as input and the provided script.

14.2 output

Before
Has Exif Profie: True
Has Color Profie: True

After
Has Profie: False
Has Color Profie: True

13.4 output

Before
Has Exif Profie: True
Has Color Profie: True

After
Has Profie: True
Has Color Profie: True

Test code

using var image = new MagickImage(inputFile);

Console.WriteLine("Before");
Console.WriteLine($"Has Exif Profie: {(image.GetExifProfile() != null)}");
Console.WriteLine($"Has Color Profie: {(image.GetColorProfile() != null)}");

var bytes = image.ToByteArray();

using var reloadedImage = new MagickImage(bytes);	
Console.WriteLine();
Console.WriteLine($"After");
Console.WriteLine($"Has Profie: {(reloadedImage.GetExifProfile() != null)}");
Console.WriteLine($"Has Color Profie: {(reloadedImage.GetColorProfile() != null)}");
	
reloadedImage.Write(outputFile);

rome

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions