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:
- Turn the pixels. Save the grid already rotated, so row one really is the top of the scene.
- 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:
- 1: Horizontal (normal). Show as stored.
- 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.
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:
- PDF files. A PDF can contain a JPG almost unchanged, but the PDF format places the image according to the page's own drawing instructions. As our test below shows, PDF renderers do not agree on whether to look at the EXIF note inside an embedded JPG.
- Tools that strip metadata. Some programs remove EXIF for privacy or size, keeping the pixels as they were. If they do not rotate the pixels first, the note is lost and the photo is sideways for good.
- Older or simpler software. Anything that decodes the raw grid without reading EXIF shows the stored layout.
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:
- 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").
- 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.
- 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
- Test image: a synthetic 400 × 300 pixel JPG, grey, with a red block in the stored top-left corner and a blue block in the stored top-right corner. Two coloured corners are enough to tell every rotation and mirror apart. Encoded with Chromium's
canvas.toBlobat quality 0.92. - Tagged copies: a script inserted an EXIF block with Orientation 1 to 8 into copies of that file. For values 3, 6 and 8 we also made little-endian copies, and copies where the EXIF block comes after the JFIF header instead of before it, since real files differ in both ways. One copy had no EXIF at all. 15 files in total.
- Checks, for each file: the value returned by the tool's own
jpegOrientationfunction (loaded unchanged from the site's source); where the red and blue blocks appear when headless Chromium 129 decodes the file; where they appear when the same file is decoded with its EXIF block removed (what an EXIF-ignoring program sees); and where they appear in two PDFs: one built the tool's way, one built by embedding the JPG bytes unchanged. Each PDF was rendered with pdf.js 4.10 in Chromium (the renderer our PDF to Images tool uses), poppler 22.02 and Ghostscript 9.55.
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:
- poppler and Ghostscript ignored the EXIF note in all cases and showed the stored layout. A photo tagged 6 appeared sideways; one tagged 3 appeared upside down.
- pdf.js in Chromium showed the picture turned according to the tag, but on a page with the stored, unturned proportions. For values 5 to 8 that means a 300 × 400 picture squeezed into a 400 × 300 page area: the right content, stretched. For values 2 to 4, where width and height do not swap, the result looked correct.
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
- Use a tool that bakes the rotation in before the note can be lost. Images to PDF does this for JPGs. Resize Image also draws each photo through the browser, which applies the tag, and saves new upright pixels without an orientation note. Compress Image works the same way, with one exception: if the compressed result would be larger than the original, it gives you the original file back unchanged, tag included.
- Check the preview, not just the thumbnail. File browsers usually apply the tag, so a thumbnail can look right while another program will not.
- Rotate in an editor that rewrites pixels when you need a file that works everywhere. A rotate button can either change only the tag or rewrite the image, and the app may not tell you which. If a photo keeps flipping between apps, the tag is the usual suspect.
- Mirrored pictures are a separate matter. If text in a photo reads backwards in every app, the pixels themselves are mirrored (for example by a camera setting), and no orientation value is involved.
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.