Takeout JSON

Fix Sideways Photos in Bulk (EXIF Orientation)

Why some photos show sideways in one app and upright in another, what the EXIF orientation tag does, and how to rotate the pixels for good.

A photo looks fine on your phone. Copy it to a USB stick and plug it into the TV, and it is on its side. Upload it to a forum, sideways. Open it in an old viewer, sideways. Same file, three different answers.

What is going on

Phones and cameras do not rotate the image when you turn the device. They record the pixels as the sensor saw them, landscape, and write a small note in EXIF saying "display this rotated 90 degrees". That note is the orientation tag. It has eight possible values, covering rotation and mirroring.

A modern viewer reads the tag and turns the picture before showing it. An old or simple viewer does not, and shows the pixels as stored. Some software reads the tag and then also rotates, giving you an upside-down photo. Some strips the tag on save without rotating the pixels, so the photo is stuck sideways from then on.

The tag was a sensible idea in 2002. It has been a source of confusion ever since.

Who ignores it

Smart TVs and digital photo frames are the usual offenders. Many read JPEGs directly off a USB stick with a decoder that predates the tag. Older Windows viewers, some web browsers before 2020, many web upload scripts, and thumbnail generators in file managers all get it wrong in one direction or the other.

The rule of thumb: anything that shows a photo without the help of a proper photo library might ignore the tag.

The fix that sticks

Rotate the pixels so the image is stored upright, then set the orientation tag to 1, which means "normal, no rotation". After that there is nothing to misread. Every viewer, old or new, shows it the right way up.

For JPEG this can be done without recompressing, because JPEG is built from 8 by 8 blocks and a 90 degree turn just rearranges them. This is called a lossless rotation. The image data is identical after the turn, only arranged differently. Edges of the image may be trimmed by a few pixels if the dimensions are not multiples of 8 or 16, which is invisible in practice.

Doing it by hand

exiftool can read the tag but does not touch pixels. For that you need jpegtran, which ships with libjpeg on every platform, or a tool built on it.

On Linux and macOS, exiftran and jhead are in the package repositories and do the whole job in one go:

jhead -autorot *.jpg

or

exiftran -ai *.jpg

Both read the tag, rotate the pixels losslessly, reset the tag to 1 and keep the rest of the EXIF. They only touch files that need it.

On Windows, JPEG Autorotate and IrfanView's batch conversion with "Auto-rotate according to EXIF" do the same. XnView MP has "JPEG Lossless Rotation" and an auto-rotate option in its batch tool, on all three platforms.

HEIC is another matter. HEIC also stores an orientation property, and even more software ignores it. There is no lossless rotate for HEIC in common tools. The practical answer is to convert to JPEG and fix the orientation at the same time, which is covered in /blog/convert-heic-to-jpg-keep-metadata.

Where Takeout fits in

Google Photos exports come out with the orientation tag intact, and Google itself displays them correctly. The problem shows when those files land on a NAS, a TV or a photo frame. If you are already fixing dates from the .json sidecars, it is the right moment to straighten the photos too, before they go anywhere.

Doing it with the app

Takeout JSON Metadata Fixer straightens photos as part of an organizing run. It is one checkbox, and it is on by default.

For every photo with an orientation tag other than 1, it rotates the pixels to match and resets the tag. Photos that are already upright are left alone. Dates, GPS and the rest of the EXIF are kept. HEIC files going through the HEIC to JPG conversion get the same treatment on the way out.

The result is a folder that displays the same everywhere: TV, photo frame, NAS web page, old laptop. Combined with the date fix and the naming templates, it is one pass instead of three tools. There is a dry run, an optional "Originals (before organizing)" folder if you work in place, and it runs offline on macOS, Windows and Linux. Free for 500 photos, then $9.99 once.

Frequently asked questions

Will rotating the pixels lower the quality?

Not for JPEG done properly. A 90 or 180 degree rotation rearranges the compressed blocks without decoding them. Some tools recompress instead, which does lose a little each time. jhead, exiftran, jpegtran and the app all do it losslessly.

Why are some photos upside down rather than sideways?

Two rotations were applied. One tool rotated the pixels but left the tag, and the viewer then rotated again. Resetting the tag to 1 fixes it.

Does this affect videos?

Videos have a similar rotation flag in their container, and TVs handle it better than they handle the EXIF tag. It is a separate problem and the tools above do not touch it. Re-encoding through ffmpeg can bake the rotation in.

If I fix orientation, will Google Photos or Apple Photos show the photos differently?

No. They already display the rotated version. After the fix, they read tag 1 and the upright pixels, and the picture looks the same as before.