Life
Copyright © 2024 Jiri Kriz, www.nosco.ch

Orientation of Photos

Comments (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":
orig 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":
orig 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: tower_horz 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.

f1 1: TopLeft
SceneImage
Top Top
Left Left
f2 2: TopRight
SceneImage
Top Top
Right Left
f3 3: BottomRight
Scene Image
Bottom Top
Right Left
f4 4: BottomLeft
SceneImage
Bottom Top
Left Left
f5 5: LeftTop
SceneImage
Left Top
Top Left
f6 6: RightTop
SceneImage
Right Top
Top Left
f7 7: RightBottom
SceneImage
Right Top
Bottom Left
f8 8: LeftBottom
SceneImage
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:

c1 1: TopLeft
c6 6: RightTop
c3 3: BottomRight
c8 8: LeftBottom
Another possibility to obtain the information about the image size and orientation is using the command:
$IM identify -format '%w %h %[orientation]' tower.jpg
684 456 RightTop

Links

Comments

New Comment