Advertisement

How the Instagram app straightens photos

Sometimes it's really an eye-opener when a developer opens the curtains just a little and lets those of us on the outside see what is going on behind the scenes. The Verge noted this morning that the Instagram engineering team had done exactly that, revealing how they went about designing and implementing the automatic image straightening that's available in Instagram for iPhone.

The option is simple in operation; one simply taps the proper icon in a menu, and the app uses data from the iPhone's accelerometer and gyroscope to determine the proper correct angle for your image. It's then possible to tweak the image just a bit more with manual controls.

When the image is rotated to create the appearance of a flat horizon, the application must zoom into the picture and do some cropping to avoid showing empty corners. The engineers note that the images would theoretically grow up to a maximum of 1.4142 times the original dimensions (that's the square root of two) if the image was rotated to 45 degrees. Since it's likely that anyone who actually tilted an image that much wanted it to be that way for aesthetic reasons, the app only auto-straightens for tilts up to a much more modest 25 degrees.

The blog post is quite fascinating in how it reveals the choices that the team made while designing the feature. Now if they could only explain why anyone would want to use the 1977 filter to ruin a perfectly good photo...