← World

Exif Image Orientation and the Behavior of Image Viewers & Browsers

←Blog ·

If you take a photo with your phone, there's a chance that you're holding it sideways or upside down. When you take the picture, your phone saves the orientation (in 90 degree rotations) to the file's metadata (exif), and then saves the image as taken; possibly upside down or sideways.

So now your jpeg is upside down, but has metadata that can be viewed as intended. The problem is that not all image viewers correctly handle that metadata and will just show the image upside down. This is unfortunate.

Of course I'm mainly concerned with images in the web browser and I can tell you that currently my iPhone Safari correctly rotates the images for me :), but that Desktop Safari doesn't :(.

It seems like this is clearly the job of the image viewer, but that it's out of my hands for now. Therefore, I decided that I'd have to rotate the image myself. Of course I'm already using imagemagick to cut thumbnails so I'll just rotate them and strip out the exif, which is important or the new image would get rotated more than we want, on the iPhone for example.

Although searching about the exif behavior didn't find me much, finding the imagemagick convert options was easier than I thought it'd be! All I added was -auto-orient and -strip to rotate the image based on the exif and then strip the exif, which it turns out I want anyways for my thumbnails.

That left me time to write this!