Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exif data not persisted after loading #1764

Open
etihwddot opened this issue Dec 2, 2024 · 1 comment
Open

Exif data not persisted after loading #1764

etihwddot opened this issue Dec 2, 2024 · 1 comment
Milestone

Comments

@etihwddot
Copy link

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

@dlemstra dlemstra added this to the 14.3.0 milestone Dec 2, 2024
@dlemstra
Copy link
Owner

dlemstra commented Dec 2, 2024

It looks like you found an edge case situation. The length of your profile is the maximum length an exif profile can have in a jpef file. But we had an incorrect check in the code of ImageMagick. I just pushed a patch to fix that and this issue will be resolved in the next release. I will add a unit test at a later point to make sure this stays fixed.

dlemstra added a commit that referenced this issue Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants