Skip to content

Image flipped when converting TIFF to PNG #1991

@bjornhellander

Description

@bjornhellander

Magick.NET version

14.11.1

Environment (Operating system, version and so on)

Windows 11

Description

I am working with a product that needs to convert TIFF files to an more browser supported image format. We have chosen PNG for now. Some images, typically originating from mobile phones, are unfortunately not converted correctly.

I have attached one example TIFF file, which to the best of my understanding is "natively" rotated 180 degrees (= I would have to tilt my head 180 degrees to be able to read the text in the image), but there are EXIF data etc which instead makes the image being presented as rotated 90 degrees counter clockwise.

After conversion to PNG format, the image is rotated the expected way (90 degrees), but also flipped vertically, which I did not expect. Not sure at all if this is a bug or if I am missing something in the code. The included code is a simplification of the real code, but includes the relevant parts.

I have tried to convert to JPG instead, but no change.

This specific example image is a single frame TIFF. I have also tried to load it directly as an MagickImage instead of a collection, but I get the same behavior.

Any help would be appreciated in getting this converted correctly!

Steps to Reproduce

using System.Reflection;
using ImageMagick;

var binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var sourceFilePath = Path.Combine(binPath, "Example.tiff");

using var sourceCollection = new MagickImageCollection(sourceFilePath);

foreach (var image in sourceCollection) {
    image.AutoOrient();
}

using var targetCollection = new MagickImageCollection();
for (var i = 0; i < sourceCollection.Count; i++) {
    targetCollection.Add(sourceCollection[i]);
}

using var targetImage = targetCollection.AppendVertically();
var imageContent = targetImage.ToByteArray(MagickFormat.Png);

var targetFilePath = Path.Combine(binPath, "Example.png");
File.WriteAllBytes(targetFilePath, imageContent);

Images

Example.tiff
Example.png

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions