[whatwg] Add "naturalOrientation" property to <img>

Tab Atkins Jr. jackalmage at gmail.com
Fri Aug 26 08:37:34 PDT 2011


Summary
=======
The <img> element should expose a readonly "naturalOrientation"
property that returns the EXIF orientation of the image (an integer
1-8), or 1 if the image has no EXIF orientation metadata or it is
corrupted or the image type doesn't expose EXIF data at all.


Background
==========
Some cameras (sometimes automatically, sometimes through an option)
record the orientation of the camera when a picture was taken.  This
data is used by many image-viewing programs to auto-rotate the image
to its "correct" orientation.  For example, if you take a picture of
the Eiffel Tower by holding your camera sideways to get more vertical
distance, you'd prefer the Tower to be vertical when you view it, not
pointing to the side like the raw image data would have you believe.

(Why do cameras express this as metadata instead of just rotating the
image data directly?  CCDs tend to stream the image data in row-major
format.  If you need to buffer the entire image before storing it so
you can do a rotation first, this may negatively affect performance in
terms of shots/second.  I dunno if this is still an issue with modern
hardware, but it apparently was with early digital cameras.)

A more thorough explanation of the EXIF orientation can be found at
<http://www.impulseadventure.com/photo/exif-orientation.html>.


Reasoning
=========
Webapps that manipulate images need to have the ability to tell when
an image should be rotated before being displayed, like desktop
image-manipulation software has.  The only way to do so currently is
to parse the binary data of the image and extract the EXIF metadata
yourself.  We can make this reasonably common need much easier by
exposing it directly.

The Google Gears API exposed this data for webpages already
(<http://code.google.com/apis/gears/api_desktop.html#Desktop>), and
according to the team, it was useful there.

~TJ


More information about the whatwg mailing list