Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Why photos taken on a modern device may appear incorrectly rotated:

Why photos taken on a modern device may appear rotated incorrectly:

Originally written as an explainiation for my Precalculus teacher as to why student's work render incorrectly in Google Classroom.

Image metadata (EXIF)

Exchangeable image file format (officially Exif, according to JEIDA/JEITA/CIPA specifications) is a standard which allows for metadata to be stored in an image or audio file. This is important, as it can store information about the image besides the image itself. Common applications include things such as date taken, shutter speed, camera type, or location, however any aribtrary key and value may be stored. A few keys are required, such as the use of the Discrete Cosine Transformation (DCT) on image/jpeg files, various algorithms and codecs used for processing RIFF files such as audio/wav A photo taken on a modern device, such as an iPhone or similar, can contain dozens if not hundreds of these tags, however those found in most images are things such as bit depth, colour palette, compression algorithms, interlacement, filters, profiles, etc.

Use of EXIF data to improve speed and memory usage

Most modern phones, although they can do tons, have shockingly low power use and small amounts of memory (ram, not disk space, although both are typically on one NAND) compared to a computer. For example, the iPads used at my school, the 1st generation iPad Mini, have a mere 512 MB of memory, while its predecessor contained a mere 256 MB. The typical computer now adays has 8, or 16 GB of RAM. This is over 32x the size of the original iPad's memory Also, mobile devices typically contain inferior CPUs as well, such as the original iPad Mini's A5 processor, clocking in at 0.8-1.0 GHz while a Intel i3 Skylake processor clocks in at 3.9 GHz. This means that a fairly low-end desktop processor is able to run nearly 4 billion computations per second. The storing of things such as rotation, etc, into the EXIF can allow for less memory use on each picture taken.

History of image rotation

On your standard DLSR or other camera, all your pictures are taken landscape. If you wanted to take one portrait, you would simply rotate your camera when you took it, and when you wanted to view it. If you wanted to use it image processing software, you would simply rotate it upon import to your computer.

Modern image rotation

Nowadays, the same phenomenon occurs. When you rotate your phone or tablet to take a picture, you are rotating the lens as well. In order to compensate for this, a 3-axis gyroscope is used. This sensor takes a small mass made of silicon is placed in an isolated chamber (think around 3 mm or so), in which a micro electro mechanical system (MEMS) is implemented. I won't go into how these work in detail, however they are able to measure the acceleration and linear motion of this silicon blob and therefore determine the angular and linear orientation of the device. The use of these sensors IC on logic board is used to determine how your device is rotated, thus rotating the GUI and such. When you take a picture, this value is stored under the orientation key in the image's EXIF data.

The orientation key and meaning

There are 8 possible values for the orientation key, as shown below:

Value Row #0 Column #0
1 Top Left Side
2* Top Right Side
3 Bottom Right Side
4* Bottom Left Side
5* Left Top
6 Right Top
7* Right Bottom
8 Left Bottom

* denotes an uncommon orientation, as the image would be flipped A value of 1 is assumed, as it requires no rotation since the first row is the top and first column is the left side. A value of 6, for example, requires a clockwise rotation of π/2 or 90º. The graphic found on shows this concept well: Graphic

What can be done to fix this

Petition whatever software is not rendering the flag correctly to add support for this feature

A few ones I know of:

  • Windows
  • Windows Photo Viewer
  • Google Classroom

For Google Classroom, simply downloading and opening elsewhere will not work. GC strips all EXIF data prior to upload.   However, you can report an issue to Google Classroom asking for this issue to be resolved.

Remove the flag and rotate manually

This can be done using ImageMagick:

mogrify input.jpg -auto-orient output.jpg

The use of mogrify instead of convert will allow overwriting of the input file.

Apps that can open images with the orientation key

  • Photos (macOS and iOS)
  • Most web browsers
  • GNU Image Manipulation Program (GIMP)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment