Why does a photo that's upright on my phone turn sideways when I upload it?
Your ID photo turns sideways the moment you attach it to an application form. I reproduced this by removing just 36 bytes from a JPEG of an upward arrow. Here is how to fix one copy for submission while keeping the original, and why a fix can end up rotating the image twice.
When I chose my ID photo, the head was at the top. On the application form’s confirmation screen, the face was lying on its side. This is common enough that the Sapporo City Board of Education in Japan warns about it in its guide for people registering as candidates for temporary teaching posts: photos taken on some smartphones end up sideways, and applicants are told to re-save them in portrait orientation. That raises the obvious question: if the photo already opens upright, what exactly are you supposed to fix and save? Sapporo City Board of Education, “Preparing your face photo” (PDF, in Japanese)
A JPEG can store pixels recorded in landscape together with an instruction that says “rotate 90 degrees clockwise when displaying.” If your photo app reads that instruction and the website you upload to ignores it, the same file appears in two different orientations. For the submission, make a copy whose pixels are arranged so that the head is at the top even when the instruction is ignored. If the photo already looks upright on your screen, there is no need to rotate it another 90 degrees.
Make one copy for submission
The desktop image editor GIMP, for example, lets you choose how to handle a photo’s orientation data when opening a JPEG. Keep the original photo and export a copy in the following order. GIMP: Import & Export preferences
- Open the original JPEG. If GIMP asks whether to rotate the image according to its orientation data, choose to rotate it. If the face is upright on screen, continue. If it is still sideways, rotate it manually until the head is at the top.
- Choose File > Export As… and give the file a different name, such as
for-submission.jpg. In the JPEG export settings, clear Save Exif data. If you want to keep the location and date taken, they remain in the original photo, which you can still use. GIMP: Handling photo metadata - On the form, select the file again, this time choosing the copy you saved under the new name. On the confirmation screen, check that the head is at the top and that the face is not stretched horizontally or vertically. Even with the correct orientation, check the width, height and file size the form requires separately.
If you are working only on a smartphone and the form also sets a limit such as “200 KB or less,” you can instead export a JPEG in the orientation the browser displays. When I took the “Original JPEG” below and saved it with this site’s image compressor set to 200 KB, the result was a 480 × 640 pixel JPEG with the arrow pointing up. The compressor does not carry over the original’s Exif data, and depending on the size limit it may also reduce the dimensions, so you can check the resulting dimensions before saving. Compress a photo into a JPEG of a set size
Removing 36 bytes turned an up arrow to the left
In a face photo, it is easy to miss a mirror flip. So I tested with a parcel label showing an upward arrow and an orange “R7” in the lower left. The three files below are real JPEGs. Open the links to see how your own browser displays each one.
| JPEG compared | Pixel width × height | Displayed |
|---|---|---|
| Original JPEG | 640×480 | ↑ up |
| Exif removed | 640×480 | ← left |
| Saved after rotation | 480×640 | ↑ up |
Inside the first file, the label is actually lying on its left side. The Orientation tag in its Exif data, the metadata recorded when a photo is taken, is 6, so the image is rotated 90 degrees clockwise for display and appears upright. To make the second file, I removed only the Exif segment from the first file and joined the rest back together without recompressing the image. The file shrank from 61,221 bytes to 61,185 bytes. When both JPEGs are decoded, every pixel of the second matches the first exactly, yet the arrow points left when it opens. The 36 bytes are the size of the Exif segment in this test file, which held nothing but the orientation; they are not the typical size of Exif data in a smartphone photo. CIPA Exif standard, image orientation, Figure 12 (PDF, Japanese edition)
This does happen in practice. The help pages of Ameba, a major Japanese blogging service, explain that photos can change orientation after posting because Exif data, including location information, is removed on upload. That produces the same result as the second file. The Sapporo guide does not explain why the orientation changes, so you cannot tell from the form’s appearance alone what processing it applies. Ameba, “Images are posted sideways” (in Japanese)
For the third file, I reversed the order of operations. I read the first file’s instruction first, rotated the pixels themselves clockwise, and then wrote a new JPEG. This time the width stored in the file is 480 and the height is 640, and there is no orientation data. Viewed side by side in a browser, the first and third files both show the arrow pointing up with “R7” in the lower left. Even so, only the first file is in trouble when its orientation data is lost.
Avoid rotating uploads twice
The same trap awaits anyone building a photo gallery on the receiving end. Suppose you make the original JPEG upright and then copy all of its metadata back, restoring the old Orientation=6 along with it. When I reattached that instruction to the third file’s pixels and opened it in a browser, the arrow that should have pointed up now pointed right: the opposite direction from the sideways image you get when the original instruction is ignored. And if you decide “rotate it if it’s landscape” by looking only at the pixel width and height, you will also rotate photos that are supposed to be landscape.
If you use Python and Pillow, apply ImageOps.exif_transpose once, while the orientation data is still present. It also handles orientation values that include a mirror flip. The example below runs in the folder where you saved the “Original JPEG” above. I created the article’s third file this way with Python 3.12 and Pillow 13.0. Pillow: exif_transpose
from PIL import Image, ImageOps
with Image.open("label-tagged.jpg") as source:
print(source.size, source.getexif().get(274)) # (640, 480) 6
upright = ImageOps.exif_transpose(source)
upright.save("submit.jpg", quality=95)
with Image.open("submit.jpg") as saved:
print(saved.size, saved.getexif().get(274)) # (480, 640) None
This example recompresses an RGB JPEG and does not pass the original Exif data to the new file. If your code produces downscaled images for submission, apply the orientation first and calculate the crop area from the resulting width and height. That also prevents accidents such as fitting a landscape crop frame onto a portrait face photo. To test it, run both the first and third files through. The expected result is that the downscaled image from either one shows the arrow pointing up with “R7” in the lower left.