7 Replies Latest reply on Mar 1, 2010 12:33 AM by mselbach2-WZFZt7

    Disable (or detect) automatic orientation rotation

    sch980

      When I open a JPEG image in Photoshop (CS3, Mac), Photoshop automatically rotates it based on the camera orientation sensor data, if available. Very nice. However, this is causing a headache for me in a set of Javascript scripts I'm working on.

       

      Very briefly, I have one script in InDesign that exports a list of all of the images used in the document, their sizes and the size and location of their containing box (i.e. the crop area). I have a second script in Photoshop that reads this list and crops and resizes the images to exact size. This works great except when the Photoshop helpfully rotates an image's orientation for me. Because InDesign doesn't also rotate the image automatically, the two disagree on the image's orientation ("0 rotation" to InDesign is landscape, while Photoshop opens it in portrait). Then all the sizes and coordinates are wrong, obviously.

       

      Is there a way to prevent Photoshop from doing that automatic rotation, or at least to detect that it has happened (including the direction of rotation) from within my script? If I can tell that it has happened, at least I can adjust my coordinates accordingly. But disabling it competely (ideally from within the script, so it would continue to work for normal interactive use) would be a lot nicer.

       

      Thanks!

        • 1. Re: Disable (or detect) automatic orientation rotation
          sch980 Level 1

          Never fails, I figure out a workaround minutes after posting...

           

          I realized I can grab the EXIF data and figure out the rotation from that. Would still be nicer to just avoid it altogether, but this will work for now...

          • 2. Re: Disable (or detect) automatic orientation rotation
            mselbach2-WZFZt7

            I'm struggling with the same problem. Reading the exif information and "correcting" the rotation would be an idea, but which Rotation-Flag do you use. If I look at the metadata in Exiftool I see a lot of different one (if the image went through a lot of apps) and all are not synchronized.

            Do you know which one Photoshop reads? Could you share your solution?

             

            Regards,

            Markus

            • 3. Re: Disable (or detect) automatic orientation rotation
              sch980 Level 1

              I don't know for sure which one Photoshop reads, and I haven't tested my solution with a wide variety of files yet, so I'm not sure how solid it is. I'm using the "Orientation" tag, and so far it seems to work.

               

              One thing I haven't figured out (and I think I must be missing something obvious) is a way to directly access exif data by key. It seems like doc.info.exif is just a big array of arrays, and I have to iterate through them doing a string match to find the one I'm looking for. Surely that can't be the only way to get at it?

              • 4. Re: Disable (or detect) automatic orientation rotation
                xbytor2 Level 4

                Although it's overkill, you can go the XMP route in PSCS4.

                • 5. Re: Disable (or detect) automatic orientation rotation
                  sch980 Level 1

                  Unfortunately, I'm still on CS3 (I usually only upgrade every other version unless there's something I really need from the new one, so I'll go to CS5 when it comes out).

                  • 6. Re: Disable (or detect) automatic orientation rotation
                    xbytor2 Level 4

                    This is code that I've used in the past.

                    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 '';
                    };
                    
                    
                    // Usage
                    
                    var exif  = new EXIF(app.activeDocument);
                    var orientation = exif.get('Orientation');
                    
                    • 7. Re: Disable (or detect) automatic orientation rotation
                      mselbach2-WZFZt7 Level 1

                      Thanks a lot for sharing, but how do we get to know if Tiff::Orientation is the only tag photoshop uses? I think I'll make a little study and apply all the different tags I know to one image and look how Photoshop treats the different ones individually and in combination.

                      I need it for a workflow where lots of images from lots of apps (ps, lightroom, gimp, camera jpg) go through a preprocessing in ps before beeing printed out.

                      Regards,

                      markus