This was originally posted on 2007-03-17 to http://andrewho.co.uk/weblog/lossless-jpeg-rotation
I've been going through photos from Halfway Hall, and a lot of them have been taken vertically. The Canon camera I use (a compact) has a gravity sensor that can autorotate photos for you as it writes them; the way it does this is by using an EXIF tag which tells you how the image should be oriented. For example, if I take a picture with the camera rotated by 90 degrees:
% identify -format '%[EXIF:Orientation]' ./IMG_1120.JPG