Photos turn sideways after removing metadata because many cameras and phones store the image in the sensor's landscape layout and record the needed rotation in a single EXIF field, the Orientation tag. When a tool deletes all EXIF without rotating the pixels, viewers have no instruction left and show the image as stored, which is sideways. The fix is to keep the EXIF Orientation tag, or to rotate the pixels and reset the tag to 1.
Here is how the tag works, what its eight values mean, how browsers handle it, and how to repair a photo that has already lost its rotation.
How EXIF orientation works
An image sensor has a fixed shape, typically wider than tall. When you hold a phone upright to take a portrait photo, the sensor is turned 90 degrees, but the camera still reads out a landscape-shaped grid of pixels. The camera knows how the device was held from its motion sensors.
The camera then has two choices. It can rotate all the pixels before saving, which costs processing time, or it can save them as captured and write a note saying "rotate this 90 degrees clockwise to display it". That note is the Orientation tag, tag number 0x0112 in the main image directory (IFD0) of the EXIF block. Many cameras and phones choose the note. Some phones rotate the pixels instead and write 1, and behavior can differ even between apps on the same device.
The tag affects only how the image is displayed. The compressed data is untouched, so a viewer that ignores the tag shows exactly what the sensor recorded.
The eight EXIF orientation values
The EXIF standard defines eight values, covering four rotations with and without a mirror flip. The names below are the ones ExifTool prints; the right column describes what a viewer must do to the stored pixels to show the photo correctly.
| Value | ExifTool name | What the viewer does | Typical cause |
|---|---|---|---|
| 1 | Horizontal (normal) | Nothing | Landscape shot, or pixels already rotated |
| 2 | Mirror horizontal | Flip left to right | Mirrored image, for example some front-camera or edited files |
| 3 | Rotate 180 | Rotate 180 degrees | Camera held upside down |
| 4 | Mirror vertical | Flip top to bottom | Rare; mirrored and upside down |
| 5 | Mirror horizontal and rotate 270 CW | Mirror, then rotate a quarter turn | Rare; mirrored portrait shot |
| 6 | Rotate 90 CW | Rotate 90 degrees clockwise | Phone or camera held upright, the most common non-1 value |
| 7 | Mirror horizontal and rotate 90 CW | Mirror, then rotate a quarter turn | Rare; mirrored portrait shot |
| 8 | Rotate 270 CW | Rotate 90 degrees counterclockwise | Device held upright the other way |
Values 5 to 8 swap width and height. A photo stored as 4032 × 3024 pixels with Orientation 6 is displayed as 3024 × 4032. That swap explains a second family of bugs: software that reads the stored dimensions but displays the rotated image ends up stretching or cropping it.
To see the raw number instead of the name, ask ExifTool for numeric output:
exiftool -Orientation -n -ImageWidth -ImageHeight photo.jpg
If the stored width is larger than the height and Orientation is 6 or 8, you are looking at a portrait photo saved sideways, and the tag is the only thing keeping it upright.
How browsers and apps handle the orientation tag
For years, browsers ignored the tag for images inside web pages, so phone photos often appeared sideways on websites while looking fine in photo apps. That changed in 2020, when Chrome 81, Safari 13.1 and Firefox switched the default of the CSS image-orientation property to from-image, meaning the EXIF tag is applied.
The CSS Images Level 3 specification also says the image's natural width and height are derived from the rotated image, so layout uses the dimensions you would expect. Authors can opt out with image-orientation: none, which shows the pixels as encoded; MDN notes that this does not override the orientation of images from a non-secure origin, for security reasons.
Outside browsers, support is uneven. Phone galleries and current desktop photo apps generally honor the tag. Some older desktop software, email clients, upload forms, print services and server-side image libraries do not, or do only when told to. ImageMagick, for example, has a specific -auto-orient option because applying the tag is a separate step.
The consequence: a photo that relies on the tag looks correct in most places, which hides the problem until the tag disappears or reaches software that ignores it.
Why naive metadata removal breaks rotation
Metadata removal tools fail at orientation in three distinct ways.
1. The tag is deleted, the pixels are not rotated
This is the classic case. A tool removes the whole EXIF block, which is the simplest way to remove GPS and device data, and the Orientation tag goes with it. The pixels are still in landscape layout, so every viewer now shows a sideways photo. ExifTool's -all= does exactly this if you do not tell it to keep the tag.
2. The pixels are rotated, the tag is kept
The opposite mistake. A tool or editor rotates the pixels to be upright but copies the original EXIF, including Orientation 6, into the new file. Viewers now apply the rotation a second time, and the photo appears sideways in the other direction. This also happened on websites around 2020: some had been rotating uploads in their own code, and once browsers began applying the tag, images were rotated twice.
3. The image is re-encoded by software that ignores the tag
Some tools decode the image, discard everything except the pixels, and save a new file. If their decoder does not apply the orientation first, the saved file is sideways and has no tag to fix it. This route also re-encodes the image, which costs quality in lossy formats.
Two correct ways to strip metadata and keep orientation
A well-behaved cleaner picks one of two strategies and applies it consistently:
| Strategy | What happens | Quality | Works in software that ignores the tag |
|---|---|---|---|
| Keep the tag | Remove all metadata except Orientation (and the color profile) | Lossless: pixels untouched | No |
| Bake in the rotation | Rotate the pixels, then set Orientation to 1 or remove it | Lossless for JPEG with jpegtran when dimensions allow; otherwise a re-encode | Yes |
Our free metadata remover uses both, depending on your choice. In the default "Keep same format" mode, it removes EXIF, XMP, IPTC and other metadata without re-encoding and keeps only two technical items: the orientation flag and the ICC color profile (see why the color profile is worth keeping). If you convert to JPEG, PNG or WebP, it re-encodes the image and applies the rotation to the pixels, so the result is upright everywhere.
With ExifTool, the "keep the tag" strategy looks like this:
exiftool -all= -tagsfromfile @ -Orientation -icc_profile -overwrite_original photo.jpg
The -tagsfromfile @ part copies the listed tags back from the original in the same operation. More variations are in the ExifTool cheat sheet.
How to fix a photo that already turned sideways
If you still have the original
Copy the Orientation tag from the original back into the cleaned file. Nothing else is restored:
exiftool -tagsfromfile original.jpg -Orientation cleaned.jpg
Or simply clean the original again with a tool that keeps orientation.
If you know which way it should face
Write the tag directly. Use 6 if the image needs a quarter turn clockwise, 8 for counterclockwise and 3 for upside down:
exiftool -Orientation=6 -n cleaned.jpg
The -n option tells ExifTool to write the number rather than interpret a text name. This adds only the single Orientation value, not any of the removed personal data.
If you want it upright everywhere
Rotate the pixels themselves. For JPEG, jpegtran can do this losslessly by rearranging the compressed blocks:
jpegtran -rotate 90 -perfect -copy none -outfile upright.jpg sideways.jpg
-perfect makes jpegtran refuse rather than alter the image if the dimensions are not a multiple of the compression block size; -trim instead drops the incomplete edge blocks, losing a few pixels at the edge. -copy none writes no metadata, which also drops the ICC profile, so add it back if the photo is not sRGB.
On Linux, jhead -autorot reads the tag, rotates the JPEG losslessly with jpegtran and resets the tag to 1. The Linux EXIF removal guide covers jhead and related tools. ImageMagick's magick photo.jpg -auto-orient upright.jpg also works, but it re-encodes the JPEG.
Whenever you rotate pixels and keep other metadata, make sure the Orientation tag ends up as 1. Otherwise viewers will rotate the already-upright photo again.
Orientation in PNG, WebP and HEIC
The Orientation tag lives in EXIF, so it can exist wherever EXIF exists: the eXIf chunk in PNG and the EXIF chunk in WebP. Neither the PNG nor the WebP specification defines rotation outside of EXIF, and software support for applying the tag in those formats is less consistent than for JPEG. For PNG and WebP on the web, upright pixels with no reliance on the tag are the safest choice.
HEIC files from iPhones have their own rotation and mirroring properties in the container, separate from EXIF. A converter that turns HEIC into JPEG must carry over the right orientation one way or the other, which is a common source of sideways conversions.
Orientation checklist before you share
- Before cleaning, run
exiftool -Orientation -nto see whether the photo relies on the tag (any value other than 1). - Use a cleaner that either keeps the Orientation tag or bakes the rotation into the pixels.
- After cleaning, open the file in a browser and in one other app to confirm it is upright.
- If you rotate pixels yourself, set the tag to 1 or remove it.
- For images going to unknown software, prefer upright pixels with Orientation 1.
- Finally, confirm the personal fields are gone; our guide to checking that metadata was really removed shows what to look for. The lossless removal guide explains why keeping the tag avoids re-encoding.