Orientation of Photos
21-Oct-2020Comments (0)
Understanding the orientation of photos is important for correct display and manipulation of JPEG images. Digital cameras usually store the orientation information in the EXIF metadata.
Introduction
I use the free program Image Magick for command-line processing
of images in Cygwin on Windows. The used version is 7.0.10.
For convenience I define the shell variable in Cygwin:
export IM="/cygdrive/c/Programs/ImageMagick-7.0.10-Q16-HDRI/magick.exe"
To get the basic information (e.g. size) about an image type in the Cygwin shell:
$IM identify image.jpg
To get the complete information including EXIF metadata use:
$IM identify -verbose image.jpg
Image size and orientation
Let us consider the image "Bridge":
$IM identify bridge.jpg
bridge.jpg JPEG 684x456 684x456+0+0 8-bit sRGB 216961B 0.016u 0:00.006
The size of the image "Bridge" is 684x456 and we interpret it
as "horizontal_width x vertical_height".
Let us consider the image "Tower":
$IM identify tower.jpg
tower.jpg JPEG 684x456 684x456+0+0 8-bit sRGB 216961B 0.016u 0:00.006
The size of the image "Tower" is 684x456 but is this "width x height" ?
It is in fact width x height of the stored image.
This image was taken with the camera in the "vertical" position
so the "width" is the vertical dimension of the dispalyed image.
The information about the orientation of the camera
is fortunately recorded in the "EXIF" metadata tag "Orientation"
of the photo.
Most applications and browsers display the image rotated according to "Orientation".
When the application GIMP opens an image in a rotated orientation
it offers the user the option to keep or to adjust the orientation.
If we choose "Keep Orientation" GIMP displays:
We obtain the "Orientation" and "Size" by issuing:
$IM identify -verbose tower.jpg | grep "Orient\|Geom"
Geometry: 684x456+0+0
Orientation: RightTop
Compare this with:
$IM identify -verbose bridge.jpg | grep "Orient\|Geom"
Geometry: 684x456+0+0
Orientation: TopLeft
The Exif tag "Orientation" has one of 8 values that are explained below.
1: TopLeft
Scene | → | Image |
---|---|---|
Top | → | Top |
Left | → | Left |
2: TopRight
Scene | → | Image |
---|---|---|
Top | → | Top |
Right | → | Left |
3: BottomRight
Scene | → | Image |
---|---|---|
Bottom | → | Top |
Right | → | Left |
4: BottomLeft
Scene | → | Image |
---|---|---|
Bottom | → | Top |
Left | → | Left |
5: LeftTop
Scene | → | Image |
---|---|---|
Left | → | Top |
Top | → | Left |
6: RightTop
Scene | → | Image |
---|---|---|
Right | → | Top |
Top | → | Left |
7: RightBottom
Scene | → | Image |
---|---|---|
Right | → | Top |
Bottom | → | Left |
8: LeftBottom
Scene | → | Image |
---|---|---|
Left | → | Top |
Bottom | → | Left |
In practical situations only the values 1, 6, 3, 8 are possible that correspond to the 4 rotations of the camera by 90 degrees:
1: TopLeft
6: RightTop
3: BottomRight
8: LeftBottom
$IM identify -format '%w %h %[orientation]' tower.jpg
684 456 RightTop
Links
- Rotate photos to be upright (Sirv Help Center)
- JPEG Rotation and EXIF Orientation (by Calvin Hass)
- Exif Orientation Tag (Sylvana.Net)
- Imagemagick: how to tell if images need to be rotated? (Stackoverflow)
New Comment