Rotate images depending on the EXIF Orientation Tag

Automatic rotation of JPG images (inclusive EXIF thumbnail) can be performed by using jhead.exe and jpegtran.exe in Windows.

jhead -ft -autorot *.JPG

All JPG-files in that folder will be rotated and file time (time and date of exposure) will be set according to the EXIF info.

-autorot
Using the ‘Orientation’ tag of the Exif header, rotate the image so that it is upright. The program ‘jpegtran’ is used to perform the rotation. This program is present in most Linux distributions. For Windows, you need to get a copy of it. After rotation, the orientation tag of the EXIF header is set to ‘1’ (normal orientation). The Exif thumbnail is also rotated as of Jhead version 2.5. Other fields of the Exif header, including dimensions are untouched, but the JPEG height/width are adjusted.
This feature is especially useful with newer digital cameras, which set the orientation field in the Exif header automatically using a built in orientation sensor in the camera.

-ft
Sets the file’s system time stamp to what is stored in the EXIF header.

This is the way to fix the Orientation EXIF tag if a picture is rotated, but the EXIF Orientation tag doesn’t reflect this change.

jhead -ft -norot DSC_XXX.JPG

-norot
Clears the Exif header rotation tag without altering the image. You may find that your images have rotation tags in them from your camera, but you already rotated them with some lossless tool without clearing the rotation tag. Now your friendly browser rotates the images on you again because the image rotation tag still indicates the image should be rotated. Use this option to fix this problem. You may also want to regenerate the thumbnail using the -rgt option.