Guide

Why a photo turns sideways after its metadata is removed

A beach JPEG displayed upright with Orientation 6, turned sideways when we removed its metadata, and displayed upright again when we rotated the stored pixels before removing the tag. Chrome applied all eight EXIF orientation values to image elements, CSS backgrounds and canvas drawings in our test.

Last updated:

Bitinz team · How we write and check our content

The stored picture and the instruction are separate

A camera file can keep its stored pixel order and use an EXIF Orientation tag to tell a viewer how to turn or mirror it, as the Exif standard defines. A browser preview can therefore look right while the stored image is still sideways, and an export that drops the tag without turning the pixels exposes the difference. We tested the tag on its own first, then repeated the failure with a photograph.

Eight tags on the same JPEG

We generated a 320 × 200 JPEG with four labelled corners: A in red, B in green, C in blue and D in yellow. ExifTool 12.57 made eight copies, setting the numeric Orientation value from 1 to 8. Every tagged copy was 5,979 bytes, and no resize or edit happened between them.

ImageMagick 7.1.1-47 generated the card. On 2026-11-16 we used Google Chrome 157.0.8103.78 in headless mode on macOS 27.0.1, at a device pixel ratio of 1.

Each copy appeared three ways on one page: an img element, a CSS background-image and a canvas filled by drawImage() from the loaded image. We waited for decoding, captured the page and checked the four coloured corners in every rendered frame: 24 checks in total.

The corner notation below reads top-left, top-right, bottom-left, bottom-right. The original is ABCD.

EXIF valueMeaningCorners in all three pathsChrome intrinsic size
1NormalABCD320 × 200
2Mirror horizontallyBADC320 × 200
3Rotate 180°DCBA320 × 200
4Mirror verticallyCDAB320 × 200
5TransposeACBD200 × 320
6Rotate 90° clockwiseCADB200 × 320
7TransverseDBCA200 × 320
8Rotate 90° anticlockwiseBDAC200 × 320

All 24 checks matched the orientation definitions. ExifTool still reported the stored dimensions as 320 × 200 for every card, while Chrome reported 200 × 320 intrinsic dimensions for values 5 to 8. Both observations help when you investigate a layout or thumbnail problem.

Orientation values 1 to 8 in three loading paths

A grid of eight panels, one per Orientation value, each showing the lettered card three times, oriented the same way.
Each numbered panel shows the same stored JPEG as an img element, a CSS background and a canvas drawing. Follow the lettered corners: values 2, 4, 5 and 7 include a reflection, which no choice between clockwise and anticlockwise rotation can reproduce.

The photograph after an upload-style export

For the photograph we made a 480 × 320 copy of a beach JPEG from Pexels, rotated its stored pixels anticlockwise and added Orientation 6. The file stored 320 × 480 pixels, but the tag made Chrome show a 480 × 320 beach view. The photo was not shot with this tag; we added it to reproduce the problem.

We then made two exports. ExifTool removed all metadata from one copy without rotating the stored image. For the other, jpegtran rotated the JPEG clockwise and removed the metadata; we chose a size whose block boundaries let the tool's -perfect option succeed.

PhotographFile bytesStored dimensionsChrome display dimensions
Sideways pixels, Orientation 673,697320 × 480480 × 320
Metadata removed only73,579320 × 480320 × 480
Rotated upright, then untagged72,993480 × 320480 × 320

Removing the metadata saved 118 bytes and broke the intended orientation. The rotated export was also smaller, but that difference includes the transform and Huffman optimization, not just the removed tag.

Orientation 6

The tagged beach photo, displayed upright.

Metadata removed

The same stored pixels without the tag, displayed sideways.

Rotated, then untagged

The rotated copy without a tag, displayed upright.
These are the three files themselves, so your browser applies their tags as it loads them. The horizon is level in the first and third; the middle file, stripped without rotation, is sideways.

Rotation and metadata removal are separate operations

EXIF Orientation describes how the stored rows and columns should be presented; the stored image does not have to be in that position already. The tag can also ask for a reflection, as four rows of the table show.

The default CSS image-orientation value is from-image, and CSS Images applies it to CSS images such as backgrounds as well. Our Chrome results followed that rule; the background was not an exception.

Canvas deserves its own check. In our test, drawing the loaded image into a canvas used the oriented image, and the canvas size followed the intrinsic dimensions Chrome reported. A pipeline that rotates an image again after an orientation-aware decode turns it twice, so inspect the decoded dimensions and output rather than assuming your own code must apply the tag.

Check the file before fixing it

We used these ExifTool arguments on the tagged and exported photographs:

exiftool -n -Orientation -ImageWidth -ImageHeight photo.jpg

The -n flag prints the numeric value, which you can match to the table. The tagged photograph returned Orientation 6, ImageWidth 320 and ImageHeight 480. The metadata-only export had the same dimensions and no Orientation result: a missing tag did not mean the picture had become upright.

Read the copy downloaded from the destination, not just the file you picked in the upload dialog, and compare its tag and dimensions with the original. In the browser, check both naturalWidth and naturalHeight; a CSS width alone does not show how the decoder interpreted the photograph.

For a general export, we also ran this ImageMagick command on the Orientation 6 file:

magick photo.jpg -auto-orient -strip -quality 94 corrected.jpg

It produced a 480 × 320 file with no orientation tag. The order matters: -auto-orient needs the tag before -strip removes it. The command writes a new JPEG and can recompress it, so keep the original and inspect the result before replacing anything.

For this specific value 6, our lossless JPEG transform was:

jpegtran -copy none -optimize -perfect -rotate 90 \
  -outfile upright.jpg photo.jpg

That only handles a clockwise quarter turn; other values need a different transform or a reflection. -perfect refuses a transform the JPEG block layout cannot perform exactly, so check its exit status instead of accepting a trimmed edge.

When Bitinz compresses a JPEG, it keeps the Orientation tag, so a tagged photo still displays upright; our Orientation 6 test file kept its tag. Colour profiles are the other metadata worth checking after an export; see the colour profile test. If a form also rejects the file for its size, this guide to upload limits covers that part.

Compress imagesMake JPG, PNG and WebP files smaller in their own format, in batches and for free.Compress images

What we did not test

We tested one Chrome version through three loading paths. Other browsers and older versions were outside this test, so the table is not a compatibility history.

FAQ

Why is my photo upright in the browser but sideways after export?
Check the Orientation tag and stored dimensions in both files. If the original needs a tag and the exported copy has lost it, orient a fresh copy while the tag is still there, then export it with the tag removed or set to 1.
Can I fix a sideways image by setting Orientation to 1?
Only if its stored pixels are already upright. Changing the tag does not rotate pixels. Open a correctly interpreted source, export it with an orientation-aware tool and check the result without relying on the old tag.
Will a CSS rotation repair the uploaded file?
It changes how that one page presents the image, not the JPEG itself. If the file must work elsewhere, prepare an upright copy instead of depending on a page's transform.

Tools in this guide

Sources

  1. Bitinz: Orientation test: files, measurements and commands (2026-11-16)
  2. CIPA: Exif 2.32, section 4.6.4: Orientation
  3. ExifTool: EXIF tags: Orientation values
  4. W3C: CSS Images Module Level 3: image-orientation
  5. MDN: image-orientation
  6. WHATWG: HTML Standard: drawing images to the canvas
  7. ImageMagick: Command-line options: -auto-orient
  8. libjpeg-turbo: jpegtran usage