why does photoshop auto-rotate images when opening?


Question

I am using scripting in Photoshop to process jpg files that are uploaded through a website. I occasionally get images that are rotated differently when you open them in Photoshop vs. Windows Previewer (or any other basic graphics program). And today I just came across one that was rotated 90 degrees and mirrored horizontally when you open it with Photoshop. This throws off the scripting b/c the image is not the expected size and orientation.

Is there a setting in Photoshop preferences to stop it from automatically rotating and mirroring these images? Or a way to strip this extra data that Photoshop is reading?

I am using Photoshop CS4 and in preferences, under Camera Raw Settings, I have it set to "disable JPEG support".

1
0
5/12/2014 9:19:00 PM

Accepted Answer

I was able to fix the auto-rotation due to the exif data with this script. (thanks to this adobe forum post) I'm sure there are more cases that need to be fixed, but this solves the ones I have run into...

EXIF = function EXIF(obj) {  
  if (obj.typename == "Document") {  
    this.exif = obj.info.exif;  
  } else {  
    this.exif = obj;  
  }  
  this.caseSensitive = false; // if needed  
};  
EXIF.prototype.get = function(tag) {  
  var exif = this.exif;  

  for (var i = 0; i < exif.length; i++) {  
    var name = exif[i][0];  
    if (name == tag) {  
      return exif[i][1];  
    }  
  }  

  if (!this.caseSensitive) {  
    tag = tag.toLowerCase().replace(/\s/g, '');  

    for (var i = 0; i < exif.length; i++) {  
      var name = exif[i][0];  
      name = name.toLowerCase().replace(/\s/g, '');  
      if (name == tag) {  
        return exif[i][1];  
      }  
    }  
  }  

  return '';  
}; 

var exif  = new EXIF(docRef);
var orientation = exif.get('Orientation');
if(orientation.substring(0,7) == 'Rotate '){
    // compensate for auto-orientation
    var rotate = parseFloat(orientation.substring(7,orientation.length));
    if(! isNaN(rotate))
        docRef.rotateCanvas(rotate*-1);
}

if(orientation == "Flip Horizontal")
    docRef.flipCanvas(Direction.HORIZONTAL);
0
6/2/2014 7:39:00 PM

Photoshop Supports the EXIF Orientation Value and the Windows Photo Viewer does not!

You can ignore the EXIF Profile Tag in Photoshop Preferences - File Handling

More info:

Beware of Rotating Photos in Windows Picture / Photo Viewer! Another surprising detail is that if you decide to perform lossless image rotation (by using the Rotate Clockwise or Rotate CounterClockwise buttons), the EXIF Orientation flag is removed! As the flag is removed/reset, if you do a rotation followed by its reverse rotation on a portrait photo (eg. rotate clockwise, then rotate counter-clockwise), the resulting orientation observed by other viewers such as Photoshop will be wrong!

http://www.impulseadventure.com/photo/exif-orientation.html


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow


Website under construction!!!
^