• jpeg binary file header with inverted width & height

    From Hui G@21:1/5 to All on Thu Mar 30 09:25:50 2017
    Hi!

    I am calculating a jpg file size by parsing it as a binary file with nodejs. The computed width height gives 4032x3024 But when viewing the image in my mac viewer, the inspector indicates a size of 3024x 4032!

    Its header 0xFFC0 block is as follow:
    ffc0 0011 080b d00f c003
    According to JPEG format, sizes should be : height = 0bd0 (i.e:3024) width = 0fc0 (i.e:4032)

    (Using Imagemagick identify program confirms this calculation: identify HJ7XFd9le.jpg HJ7XFd9le.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 380KB 0.000u 0:00.000)


    How can i compute the accurate size programmatically by parsing the file as a binary file?

    Thanks!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nobody@21:1/5 to Hui G on Wed Apr 19 04:45:28 2017
    On Thu, 30 Mar 2017 09:25:50 -0700, Hui G wrote:

    I am calculating a jpg file size by parsing it as a binary file with
    nodejs. The computed width height gives 4032x3024 But when viewing the
    image in my mac viewer, the inspector indicates a size of 3024x 4032!

    The difference is likely due to an extension chunk indicating that the
    image is rotated.

    If you take a photo on a smartphone, the raw image dimensions will
    typically match that of the CCD, but the software will indicate whether
    the image is "portrait" (height > width) or "landscape" (width > height)
    based upon the physical orientation of the device at the time that the
    photo was taken (determined from the accelerometers).

    The Mac's photo viewer is presumably reporting the post-rotation
    dimensions rather than the dimensions of the image that's actually stored
    in the file.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)