SixLabors / ImageSharp

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

I have encountered a bug with heigh and width of image #2736

Closed sodiqjonovich closed 4 weeks ago

sodiqjonovich commented 2 months ago

Prerequisites

ImageSharp version

3.1.4

Other ImageSharp packages and versions

3.1.4

Environment (Operating system, version and so on)

Windows 11, Linux Ubuntu

.NET Framework version

.net6

Description

image

This is my picture, in here width = 4282pixels, height = 5712 pixels. But In ImageSharp showing wrong

image

Steps to Reproduce

using (var imageSharp = SixLabors.ImageSharp.Image.Load(image.OpenReadStream())) { var width = imageSharp.Width; var height = imageSharp.Height;

// Check image ratio
double allowedRatio = 0.01;
var ratio = (double) width / height;
if (Math.Abs(ratio - ((double)_ratioX / _ratioY)) >= allowedRatio)
{
    return new ValidationResult($"Image ratio should be {_ratioX}:{_ratioY}");
}

}

Images

image image

tocsoft commented 2 months ago

this is most likely due to some metadata tag setting a rotation (EXIF). We don't handle that automagically like windows/viewer software does.

You will want to call the img.Mutate(p=>p.AutoOrient()) helper to force the pixel into the correct orientation.

sodiqjonovich commented 2 months ago

I should only get width and height of image, how can i get via this library

tiesont commented 2 months ago

Also: #2644

JimBobSquarePants commented 2 months ago

I should only get width and height of image, how can i get via this library

The height and width of the image are the ones reported by the library. This is exactly the same as other libraries. If you want orientation dimensions you will have to check the image metadata.