Menu

#4 Autorotate via Exif information

open
nobody
None
5
2007-06-25
2007-06-25
Ivans Chou
No

If you use libexif (http://libexif.sourceforge.net/) you can read the exif header information and look for the "Orientation" item. This field will be populated with one of eight values, though only four of which is actually valid for most digital photography (per this URL: http://www.impulseadventure.com/photo/exif-orientation.html\).

It would be great to be able to have images automatically rotated to the correct orientation based on the EXIF header information.

Basically the values are: 6-rotate 90 CCW, 3-rotate 180, 8-rotate 270 CCW.

Sample code using would be something like:

// in the main:
#include <exif.h>

// somewhere at the top of main:
exif_init ( malloc, free, realloc );

// where you read the jpeg
exif_data_t* ed;
exif_record_t* er;
ed = exif_parse_file ( argv[--argc] );
er = exif_find_record ( ed, "Orientation" );
switch ( er->rec_data.l )
{
case 8:
myRotation = 270;
break;
case 3:
myRotation = 180;
break;
case 6:
myRotation = 90;
break;
}

Caveat on libexif. I downloaded the tarball release and found that exif.c and exif.h were missing from the release, and I had to manually download those two files from the SourceForge CVS repository.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.