JPG EXIF Orientation: Why Photos Rotate After Upload

November 08, 2026 · HENRICK HEILESEN · JPEG Troubleshooting

Explain orientation tags, pixel baking, metadata stripping and a cross-platform correction workflow.

How the Orientation Tag Separates Display from Storage

A JPEG file begins with the Start Of Image marker (FFD8), followed by marker segments defined in Annex B of ITU-T T.81 [1]. EXIF metadata resides in an APP1 marker (FFE1), not in the core JPEG bitstream. Inside that segment, the IFD0 directory holds tag 0x0112, the orientation tag.

The tag stores an integer from 1 to 8:

  • 1 — Normal (no rotation)
  • 2 — Flipped horizontally
  • 3 — Rotated 180°
  • 4 — Flipped vertically
  • 5 — Flipped horizontally, then rotated 90° CCW
  • 6 — Rotated 90° CW
  • 7 — Flipped horizontally, then rotated 90° CW
  • 8 — Rotated 90° CCW

Values 3, 6, and 8 account for most upload rotation failures. A camera writes the tag to record device orientation at capture time. A desktop photo viewer reads the tag and rotates the display. A web service that strips EXIF or ignores the tag shows the raw pixel grid, which appears rotated.

Why Pixel Baking Is the Only Universal Fix

Metadata tags are advisory. Any pipeline that strips EXIF, re-encodes without preserving APP1 segments, or uses a decoder that does not parse IFD0 will display stored pixels as-is.

Baking applies the rotation to the pixel matrix and sets the orientation tag to 1 or removes it. After baking, the image data matches the intended visual orientation regardless of software.

Baking is destructive. Rotating a 6000×4000 image by 90° produces a 4000×6000 image. The original pixel arrangement is gone. Keep a copy of the unmodified file if the original sensor data matters.

Three Failure Modes

The Strip-and-Show Pipeline

CMS platforms, social media uploaders, and print portals often strip all EXIF metadata on ingest. They serve raw pixel data without orientation instructions.

Observable check: Download the image from the platform after upload. Open it in a viewer that ignores EXIF, such as feh on Linux or a plain <img> tag in a minimal HTML page. If it appears rotated, the platform stripped the tag.

The Browser Disconnect

Desktop browsers handle EXIF orientation inconsistently. Safari on macOS honors the tag in <img> elements. Chrome on Windows does not. The same file can appear correct in one browser and rotated in another on the same machine.

Observable check: Open the same JPEG in Chrome, Firefox, and Safari. If one shows rotation and another does not, the tag is present but not universally supported.

The Mobile Upload Shortcut

iOS and Android cameras write orientation tags when the device is rotated during capture. The phone gallery app rotates the display. When you upload directly from the gallery, the raw file retains the original pixel orientation plus the tag. The receiving service sees raw pixels.

Observable check: Locate the file on the phone using a file manager, not the gallery. If the thumbnail shows the image on its side, the raw pixels are rotated.

Correction Workflow

Step 1: Identify the Current Orientation Tag

exiftool -Orientation photo.jpg

Output such as Orientation: Rotate 90 CW confirms a non-normal tag. If the output reads Horizontal (normal) or Orientation: 1, the tag is not causing the rotation. Investigate other causes, such as a pre-rotated pixel grid or a cropped preview thumbnail.

Step 2: Bake the Rotation (macOS / Linux)

ImageMagick applies the rotation and resets the tag:

convert photo.jpg -auto-orient -quality 95 baked_photo.jpg

-auto-orient reads the EXIF orientation tag, rotates pixel data to match, and writes tag value 1. JPEG decompression and re-compression occur. Use -quality 95 or higher to limit generation loss.

Step 3: Bake the Rotation (Windows)

IrfanView with the JPG Lossless Operations plugin applies rotation without re-compression for 90° multiples:

  1. Open the image.
  2. Select Image > Lossless Operations > Auto Rotate by EXIF.
  3. Save as a new file.

If the plugin is unavailable, use Image > Resize/Resample, set rotation manually, and save at quality 98.

Step 4: Strip the Remaining Orientation Tag

Some tools leave the old tag value after baking. Remove it explicitly:

exiftool -Orientation= baked_photo.jpg

This sets the tag to empty. Most decoders default to Normal when the tag is absent.

Step 5: Verify on Three Targets

  1. Open the baked file in Chrome on Windows or Linux.
  2. Open it on a phone in a mobile browser, not the gallery app.
  3. Upload it to the target platform and check the preview.

If all three display the correct orientation, the file is safe for any pipeline.

Limitations

  • If the original file has no orientation tag and the pixels are already rotated, baking does nothing. Manually rotate to the correct angle.
  • Each bake-and-save cycle adds JPEG generation loss. Start from the highest-quality source available.
  • If the orientation tag contains a non-standard value such as 0 or 9, tools may crash or skip the file. Run exiftool -validate photo.jpg before attempting rotation.
  • Lossless rotation without re-compression works only for multiples of 90°. Any other angle requires full decompression and re-compression.

When to Leave the Tag in Place

If a service explicitly documents EXIF orientation support — some print shops and portfolio hosts — test before baking. Upload a test image, download it back, and verify the service preserved the tag and rendered the rotation.

For pipelines serving images to mobile apps, do not rely on the tag. iOS native image decoders and Android's BitmapFactory do not consistently read EXIF orientation. Bake before serving.

For batch processing, ImageMagick's -auto-orient handles all eight orientation cases. Run with -verbose on a subset to confirm behavior before applying changes to the full set.

The JPEG standard does not mandate orientation handling. The EXIF orientation tag is a convention that different software stacks implement differently. Making pixel data match the intended view and removing the instruction that told anyone otherwise is the only guarantee of consistent display.

References

[1] ITU-T. (1992). Information Technology – Digital Compression and Coding of Continuous-Tone Still Images – Requirements and Guidelines. ITU-T Recommendation T.81. https://www.w3.org/Graphics/JPEG/itu-t81.pdf