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

image.MetaData.HorizontalResolution is not correct, returns 1, and file properties shows 96 #490

Closed
steven-gong opened this issue Mar 16, 2018 · 5 comments

Comments

@steven-gong
Copy link

steven-gong commented Mar 16, 2018

Prerequisites

  • [v] I have written a descriptive issue title
  • [v] I have verified that I am running the latest version of ImageSharp
  • [v] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [v] I have searched open and closed issues to ensure it has not already been reported

Description

I'm using the imagesharp to load a test image, and validate its resolution, however the tested image got both vertical and horizontal resolutions are 96, but the loaded image MetaData resolutions by ImageSharp are 1, which is expected to be 96.

Steps to Reproduce

var fileStream = new FileStream("96Resolution.jpg", FileMode.Open);
IImageFormat format;
var image = Image.Load(fileStream, out format);
if (image.MetaData.HorizontalResolution < 72){ .... }

Here image.MetaData.HorizontalResolution = 1
Just attached my test image.
invalidresolution

System Configuration

  • ImageSharp version: 1.0.0-beta0002
  • Other ImageSharp packages and versions:
  • Environment (Operating system, version and so on): Windows10, Visual Studio 2017
  • .NET Framework version: .NetCore 2.0
  • Additional information:
@JimBobSquarePants
Copy link
Member

Hi @steven-gong

Can you please try this again using the issue template. We cannot accept issues without them

@JimBobSquarePants
Copy link
Member

Thanks, that's much better!

Can you test the image against the latest build. I'm fairly certain we fixed this since beta 2

Cheers

James

@NickyM
Copy link

NickyM commented Jun 15, 2018

This bug is present in both beta 3 and beta 4.

Using this image:
aa834718-85e0-43e8-91d3-fc3722f6c7b8

And this code:

using (var image = Image.Load(filePath))
{
    var size = image.Size();
    toReturn.Image_Height = size.Height;
    toReturn.Image_Width = size.Width;

    toReturn.Image_HorizontalResolution = image.MetaData.HorizontalResolution;
    toReturn.Image_VerticalResolution = image.MetaData.VerticalResolution;
}

@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Jun 16, 2018

Hi @steven-gong @NickyM

Thanks for reporting this.

This is interesting. We're actually reading the correct density units from the image but what we are reporting back though is the aspect ratio not the resolution.

https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#Resolution_and_aspect_ratio

Here's the second image using aspect ratio density units.
1x1

Here's an image using the resolution density units.
96x96

I'm wondering whether there is a better way of expressing this. @dlemstra how does ImageMagick report it back to the user?

Perhaps we should add the following enumeration to the IImageInfo interface?

    /// <summary>
    /// Provides enumeration of available pixel density units.
    /// </summary>
    public enum DensityUnits : byte
    {
        /// <summary>
        /// No units; width:height pixel aspect ratio = Ydensity:Xdensity
        /// </summary>
        AspectRatio = 0,

        /// <summary>
        /// Pixels per inch (2.54 cm)
        /// </summary>
        PixelsPerInch = 1, // Other image formats would default to this.

        /// <summary>
        /// Pixels per centimeter.
        /// </summary>
        PixelsPerCentimeter = 2
    }

@JimBobSquarePants
Copy link
Member

Hey @steven-gong @NickyM

I've introduced #649 to improve resolution handling within the library. Once merged you'll also know what unit of measurement is used when querying resolution metadata.

Explorer is talking absolute nonsense for both the images in this issue.

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

3 participants