6 */ /** * Implementation of hook_imagecache_actions. * * @return array * An array of information on the actions implemented by a module. */ function imagecache_autorotate_imagecache_actions() { $actions = array( 'imagecache_autorotate' => array( 'name' => 'Autorotate', 'description' => t('Add autorotate image based on EXIF Orientation.'), ), ); return $actions; } /** * Declare dummy form, since we have no settings. */ function imagecache_autorotate_form() { $form = array(); $form['help'] = array( '#type' => 'markup', '#value' => "

There are no user-configurable options for this process.

Certain cameras can embed orientation information into image files when they save them. This information is embedded in an EXIF tag and can be used to rotate images to their correct position for display.

Not all cameras or images contain this information. This process is only useful for those that do.

The expected/supported values are
Tag: 0x0112 Orientation

EXIF Reference

", ); return $form; } /** * Autorotate image based on EXIF Orientation tag. * * See code at * http://sylvana.net/jpegcrop/exif_orientation.html * * and reference at * http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html * * @todo: * Add horizontal and vertical flips etc. * Need to create sample set for tests. */ function imagecache_autorotate_image(&$image, $data) { // Test to see if EXIF is supported for image type (e.g. not PNG). // @todo: Add mimetype for TIFF also if ($image->info['mime_type'] == 'image/jpeg') { $exif = exif_read_data($image->source); //debug(__FUNCTION__ .': exif[Orientation]='. print_r($exif['Orientation'], TRUE)); if (! isset($exif['Orientation'])) return TRUE; switch($exif['Orientation']) { case 3: $degrees = 180; break; case 6: $degrees = 90; // Rotate 90 CW break; case 8: $degrees = 270; // Rotate 270 CW break; default: $degrees = 0; } if ($degrees) { //debug(__FUNCTION__ .': rotating degrees='. $degrees); imageapi_image_rotate($image, $degrees); } } return TRUE; }