TabGarden

Guides

Why Phone Photos Turn Sideways: EXIF Orientation Explained and Tested

The 8 EXIF orientation values, why one photo looks upright in one app and sideways in another, and a reproducible test of how TabGarden handles it.

You take a photo with your phone held upright. It looks fine in your gallery. Then you put it into a document, a website form or a PDF, and it shows up lying on its side. Nothing is wrong with the photo, and nothing is wrong with your phone. Two programs simply disagree about one small number stored inside the file: the EXIF orientation tag.

This guide explains what that tag is, lists its eight values, shows why the same file can look different in different programs, and reports a test we ran on how the Images to PDF tool deals with it.

Two ways to store an upright photo

A JPG file holds a grid of pixels, stored row by row from the top-left corner. There are two ways to end up with a photo that looks upright:

  1. Turn the pixels. Save the grid already rotated, so row one really is the top of the scene.
  2. Keep the pixels, add a note. Save the grid the way the camera sensor read it, and add a small tag saying "when you show this, turn it 90 degrees clockwise".

The second way is cheaper for a camera, because rotating a large image takes time and memory, and it avoids recompressing the picture. The note lives in the file's EXIF block, the same metadata area that holds the date, the camera model and other details. The tag is called Orientation (tag number 0x0112).

A program that reads the note shows the photo upright. A program that ignores it shows the grid exactly as stored, which for a phone photo held upright often means sideways.

The eight orientation values

The tag holds a number from 1 to 8. The ExifTool tag reference lists them as:

Values 1, 3, 6 and 8 are plain rotations, the kind you get by turning a camera. Values 2, 4, 5 and 7 add a mirror flip. For values 5 to 8 the width and height swap: a photo stored as 4032 × 3024 pixels with value 6 is meant to be shown as 3024 × 4032.

A photo with no EXIF block, or with no Orientation tag, is treated as value 1.

Why some apps show photos sideways

Every program that displays or converts an image has to decide whether to apply the tag. Web browsers today apply it by default: the CSS property image-orientation has the initial value from-image, which MDN describes as using the EXIF information to rotate the image. That is why a sideways-stored photo looks right on most web pages.

Problems appear where the pixels leave the image file and go somewhere the note does not follow:

So the fix is not to "repair" the photo but to make sure that, at the moment the note would be lost, the pixels are turned for real.

How TabGarden handles it

We read the code of the Images to PDF tool. For each JPG it does this:

  1. It reads the file's bytes and looks for the EXIF block, then for the Orientation tag inside it. It handles both byte orders EXIF allows ("big-endian" and "little-endian").
  2. If the value is 1 (or there is no tag), it puts the original JPG bytes into the PDF unchanged. No recompression, no quality loss.
  3. If the value is anything else, it lets the browser decode the photo (which applies the tag), draws the upright result on a canvas, and saves that as a new JPG at quality 0.92. That JPG has upright pixels and no orientation note, so every PDF viewer shows the same thing.

PNG files are embedded as they are, and WebP files are decoded by the browser and re-saved as PNG. The tool does not read orientation data from PNG files; we did not test PNG or WebP files that carry orientation information.

The cost of step 3 is one round of JPG recompression for rotated photos. At quality 0.92 that is usually hard to see, but it is a real change to the pixels, which is why upright photos are left untouched.

A reproducible test

We wanted to check two things: that the tool reads every value correctly, and what actually happens in PDF viewers with and without this handling.

Method

The scripts (measure.cjs, crosscheck.py) and the results are in the site's research/phone-photos-sideways-exif-orientation/ folder.

Results

The tool read the right value in all 15 files: 1 to 8 as written, regardless of byte order or segment position, and 1 for the file with no EXIF.

Chromium applied every value as the ExifTool table describes. With value 6, for example, the decoded image was 300 × 400 with red at the top right and blue at the bottom right, which is the stored picture turned 90 degrees clockwise. With value 2, red and blue swapped sides (a mirror). With the EXIF block removed, every file showed the stored layout: 400 × 300, red top left, blue top right.

PDFs built the tool's way looked the same in all three renderers, and matched Chromium's upright view for all eight values. pdf.js, poppler and Ghostscript agreed on size and on the position of both blocks in every case.

PDFs built by embedding the JPG unchanged did not look the same everywhere:

So a PDF made without orientation handling can look fine in one viewer, stretched in another and sideways in a third, from the same file. Building the PDF from upright pixels removes the disagreement.

A side note for developers: in Chromium 129, createImageBitmap(blob, { imageOrientation: 'none' }) still applied the EXIF orientation in our test. If you need the stored layout in a browser, removing the EXIF segment before decoding worked.

How to avoid sideways photos

Common questions

Will the tool rotate a photo that is upright but has the wrong tag?

The tool trusts the tag, the same way browsers do. If a file is upright in your gallery, it will be upright in the PDF, because the gallery and the browser read the same tag.

Does the rotated copy lose the rest of the EXIF data?

The re-saved JPG inside the PDF has no EXIF block at all, so the camera model, date and any location data are not carried into the PDF for rotated photos. Upright JPGs are embedded byte for byte, so their EXIF block is inside the PDF file, even though PDF viewers do not display it. If you want metadata gone from every photo, run them through Resize Image first (at their current width if you do not want them smaller), which writes fresh files without EXIF.

Is the quality loss from re-encoding visible?

The tool re-encodes at quality 0.92. For how quality settings relate to file size and visible artefacts, see image quality vs file size.

My photo is in a PDF already and shows sideways. Can I fix it there?

The orientation decision was made when the PDF was built. The simplest fix is to rebuild the PDF from the original photos with a tool that applies the tag, such as Images to PDF. For scanning tips that avoid the problem from the start, see scan documents to PDF with phone photos.