Discussion:
jpeg binary file header with inverted width & height
(too old to reply)
Hui G
2017-03-30 16:25:50 UTC
Permalink
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!
Nobody
2017-04-19 03:45:28 UTC
Permalink
Post by Hui G
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.

Loading...