*** OLDimagemagick_advanced.module	2013-03-01 13:52:41.530786516 -0500
--- imagemagick_advanced.module	2013-03-01 14:19:27.601062552 -0500
***************
*** 92,97 ****
--- 92,111 ----
  }
  
  /**
+  * Auto orient an image.
+  *
+  * @param $image
+  *   An image object. The $image->resource value will be modified by this call.
+  *
+  * @return
+  *   TRUE or FALSE, based on success.
+  */
+ function image_imagemagick_auto_orient(stdClass $image) {
+   $image->ops[] = '-auto-orient';
+   return TRUE;
+ }
+ 
+ /**
   * Sharpens an image.
   *
   * @param $image
***************
*** 144,152 ****
  function imagemagick_advanced_image_effect_info() {
    $effects['imagemagick_strip'] = array(
      'label' => t('Strip metadata'),
!     'help' => t('Resizing will make images an exact set of dimensions. This may cause images to be stretched or shrunk disproportionately.'),
      'effect callback' => 'imagemagick_advanced_strip_effect',
    );
    return $effects;
  }
  
--- 158,171 ----
  function imagemagick_advanced_image_effect_info() {
    $effects['imagemagick_strip'] = array(
      'label' => t('Strip metadata'),
!     'help' => t('Strip metadata from an image.'),
      'effect callback' => 'imagemagick_advanced_strip_effect',
    );
+   $effects['imagemagick_auto_orient'] = array(
+     'label' => t('Auto orient'),
+     'help' => t('Automatically rotates image according to orientation flag set by many phones and digital cameras.'),
+     'effect callback' => 'imagemagick_advanced_auto_orient_effect',
+   );
    return $effects;
  }
  
***************
*** 157,163 ****
   *   An image object returned by image_load().
   *
   * @return
!  *   TRUE on success. FALSE on failure to resize image.
   *
   * @see imagemagick_strip()
   */
--- 176,182 ----
   *   An image object returned by image_load().
   *
   * @return
!  *   TRUE on success. FALSE on failure.
   *
   * @see imagemagick_strip()
   */
***************
*** 167,172 ****
--- 186,215 ----
        '%toolkit' => $image->toolkit,
        '%path' => $image->source,
        '%mimetype' => $image->info['mime_type'],
+       '%dimensions' => $image->info['height'] . 'x' . $image->info['height'],
+     ), WATCHDOG_ERROR);
+     return FALSE;
+   }
+   return TRUE;
+ }
+ 
+ /**
+  * Image effect callback; Auto orients an image resource.
+  *
+  * @param $image
+  *   An image object returned by image_load().
+  *
+  * @return
+  *   TRUE on success. FALSE on failure.
+  *
+  * @see imagemagick_auto_orient()
+  */
+ function imagemagick_advanced_auto_orient_effect($image) {
+   if (!image_toolkit_invoke('auto_orient', $image)) {
+     watchdog('imagemagick', 'Image auto orient failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array(
+       '%toolkit' => $image->toolkit,
+       '%path' => $image->source,
+       '%mimetype' => $image->info['mime_type'],
        '%dimensions' => $image->info['height'] . 'x' . $image->info['height'],
      ), WATCHDOG_ERROR);
      return FALSE;
