Cameras and phones usually save pixels in the sensor's native wide layout and write how the device was held into the Orientation tag. The viewer then rotates or mirrors the image on display. A phone held upright typically writes 6.
The tag sits in IFD0 as a 16-bit unsigned integer, in JPEG and TIFF files alike. Here are the values with the text ExifTool prints (-n gives the number):
| Value | ExifTool prints |
|---|---|
| 1 | Horizontal (normal) |
| 2 | Mirror horizontal |
| 3 | Rotate 180 |
| 4 | Mirror vertical |
| 5 | Mirror horizontal and rotate 270 CW |
| 6 | Rotate 90 CW |
| 7 | Mirror horizontal and rotate 90 CW |
| 8 | Rotate 270 CW |
"Rotate 90 CW" is the instruction for the viewer: turn the stored image 90 degrees clockwise to display it upright. The mirrored values are rare in camera files.
Who honors it
Phone galleries, macOS Preview, Windows Photos and current browsers do; CSS has defaulted to image-orientation: from-image since 2020. Code is another story. Pillow returns the stored pixels until you call ImageOps.exif_transpose(): the same test file opened as 1200x800 and came back as 800x1200 after the call. Thumbnailers and upload scripts that skip that step produce sideways images.
Why stripping metadata can rotate a photo
Delete the tag and viewers show the raw sensor layout, so the portrait shot lies on its side. Any full strip does this, including exiftool -all= and our metadata remover. Two ways around it:
# bake the rotation into the pixels (re-encodes the JPEG), Orientation becomes 1
convert photo.jpg -auto-orient upright.jpg
# or strip everything but keep the tag
exiftool -all= -tagsfromfile @ -Orientation photo.jpgThe second command left only Orientation (still Rotate 90 CW) plus the resolution defaults ExifTool writes into a fresh IFD0. The metadata removal guide covers the rest of the workflow.
You can read and change the tag in the EXIF editor for JPEG and TIFF. That changes how viewers display the image, not the pixels, and the stored width and height stay the same.