SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.31k stars 846 forks source link

The width and height of my image are reversed #2644

Closed Zhao-Michael closed 7 months ago

Zhao-Michael commented 7 months ago

Prerequisites

ImageSharp version

3.1.2

Other ImageSharp packages and versions

N/A

Environment (Operating system, version and so on)

Win10 22H2

.NET Framework version

.Net8.0

Description

The width and height of my image are reversed, the width should be 1080, and Height should be 1440.

image

Steps to Reproduce

Just load the attached image in 'IMG1.zip', And Check the Width and Height of the image:

using SixLabors.ImageSharp; using SixLabors.ImageSharp.Metadata.Profiles.Exif; using SixLabors.ImageSharp.Processing;

var path = @"IMG1.jpg"; using var image = Image.Load(path); Console.WriteLine(image.Width.ToString() + " x " + image.Height.ToString());

Images

IMG1.zip

JimBobSquarePants commented 7 months ago

The width and height will be accurate. The EXIF metadata will indicate that the image is rotated.

Zhao-Michael commented 7 months ago

So ImageSharp will not help to reverse width and height? Since I see most of image viewer software like PS, window10 photos can handle it well...

tocsoft commented 7 months ago

if you run the img.Mutate(x=>x.AutoOrient()) it'll fix up the pixel data to be orientated as expected.

Note this is a difference stemming from audience expectations between image viewing and programmatic image manipulation. Image viewers are processing the data for humans to understand and physically look at where as ImageSharp is for manipulating the individual pixel data. Rotating the pixel data in memory (rather that adding a tag to tell a viewer to do it for you, which is the case here) would increase memory usage and loading time in places where not everyone will want/need that behaviour.

tiesont commented 7 months ago

For what it's worth, this has been discussed before. @JimBobSquarePants has an example of a quick program you can write to verify what they're saying, in #1613