7 Replies Latest reply on Feb 19, 2011 7:34 PM by JJMack

    Rotate if width smaller than height?

    phosphorspitter Level 1

      I have an Action for Two 5x7s on one sheet of paper. The Backgrounds are of two kinds Horizontal and Vertical. To run the action I need to rotate the vertical background CW with an action. I was thinking in a script like: if width smaller than height rotate CW.

      With such a script incorporated into the Package action I couldstream line the process.

      Can a script do this rotation?

        • 1. Re: Rotate if width smaller than height?
          c.pfaffenbichler Level 9

          You could try this:


          #target photoshop
          if (app.documents.length > 0) {
               var myDocument = app.activeDocument;
               if (myDocument.height > myDocument.width) {

          • 2. Re: Rotate if width smaller than height?
            JJMack Most Valuable Participant

            Here is a script I worked on for use in actions its ment to be run twice orient.jsx




            // Copyright 2002-2003. Adobe Systems, Incorporated. All rights reserved.

            // This scripts demonstrates how to rotate a layer 90 degrees clockwise.

            // Original file came from PSCS scripting\samples\javascript\RotateLayer.js


            // Variation Copyright(c)Douglas Cody, 2004, All Rights Reserved.

            // http://www.clikphoto.com


            // Updataed John J McAssey 2008 - 2009 http://mouseprints.net


            // This script is designed to be used by a Photoshop Action twice

            // A good pratice to use when creating an actions that use this scipt is for the action

            // not to do a save or play some other action between its two useages of this Script.


            // This script will look at the document orientation (portrait vs landscape)

            // On the first execution, if the document is a portrait, it will be rotated

            // to a horizontal.

            // On the second execution, a rotated document will be

            // restored to a vertical. This effectively toggles the orientation ONLY if

            // the original document started out as a portrait.


            // NOTE: Meta-data Info Instructions field is modified to hold an interim state.


            // Bug Fixes by JJMack, 2008, with the original code Square images were always

            // rotated -90 and marked "rotate back" with two executions you wound up with

            // an upside down image... The original code would also fail to rotate an image

            // back if the action added canvas and change the rotated images aspect ratio

            // to other then landscape. Again you wind up with a marked upside down image.

            // In addition units the compare could fail because the script did not set the

            // units to use for rulers.  


            // Updated in 2009 JJMack to remove some restrictions try make it near bullet proof 

            // presserve any data that might have been in Files metada Info Instructions field

            // this also allows more one run twice scripts to be used on a document.






            <about>$$$/JavaScripts/orient/About=JJMack's Orient^r^rCopyright 2009 Mouseprints.^r^rRun twice script utility for action.^rNOTE:Don't play other actions between runs!^rFirst Run records orintation and rotate Protrait to Landscape^rSecond Run removes orintation recorded and rotates Portrats back.</about>

            <category>JJMack's Action Run Twice Utility</category>




            if (app.documents.length > 0) {

                    var orintation = '';

            if (app.activeDocument.info.instructions.indexOf("<orient>") == -1 ) { // No Footprint



            var orig_ruler_units = app.preferences.rulerUnits; // Save ruler units

            app.preferences.rulerUnits = Units.PIXELS; // Set ruler units to PIXELS


            // Add Foot Print to  metadata info instructions and rorate protrait documents

            // alert( " Width = " + app.activeDocument.width + " Height = " + app.activeDocument.height );

            if (app.activeDocument.width < app.activeDocument.height) { // portrait 


            app.activeDocument.info.instructions = app.activeDocument.info.instructions += "<orient>portrait</orient>";


            else { app.activeDocument.info.instructions += "<orient>landscape or square</orient>"; } // not portrait

            // Reset units to original settings


            app.preferences.rulerUnits = orig_ruler_units; // Restore ruler units


            else {


            // Retreive saved orintation and rotate portrait back up

            orientOffset = app.activeDocument.info.instructions.indexOf("<orient>") + "<orient>".length;

            orientLength = app.activeDocument.info.instructions.indexOf("</orient>") -orientOffset;

            orintation = app.activeDocument.info.instructions.substr(orientOffset, orientLength);

            if ( orintation == "portrait" ) { app.activeDocument.rotateCanvas(90.0); }


            // Remove footprint from metadata info instructions

            before = app.activeDocument.info.instructions.substr(0,app.activeDocument.info.instructions.indexO f("<orient>"));

            afterOffset = app.activeDocument.info.instructions.indexOf("</orient>") + "</orient>".length;

            after = app.activeDocument.info.instructions.substr(afterOffset, app.activeDocument.info.instructions.length - afterOffset);

            app.activeDocument.info.instructions = before + after;



            else { alert("You must have at least one open document to run this script!"); }

            1 person found this helpful
            • 3. Re: Rotate if width smaller than height?
              phosphorspitter Level 1

              Works perfect

              Thank you.

              • 4. Re: Rotate if width smaller than height?
                phosphorspitter Level 1

                Thank you very much.There might be a use for this one further done the line.

                The reason I can not use this script because it rotates it back but my Package Action closes the picture after rotating and pasting

                Pfaffenbichler's script does what I need and I am already using it.

                Thank you again for your time and help.

                • 5. Re: Rotate if width smaller than height?
                  JJMack Most Valuable Participant

                  Right there is a need for both scripts.  The Simple rotate to Landscape script and when you need a one way rotation and when you need a rotate portrait to landscale to proform some steps and would like to rotate Landscape that were Portrait you need the more complicated one.  Its a save and restore type script for actions. I have several like that in my Photoshop crafting Actions Package.




                  Action Actions Palette Tips.txt

                  Action Creation Guidelines.txt

                  Action Dealing with Image Size.txt

                  Action Enhanced via Scripted Photoshop Functions.txt

                  CraftedActions.atn Sample Action set includes an example Watermarking action

                  Sample Actions.txt Photoshop CraftedActions set saved as a text file. This file has some additional comments I inserted describing how the actions work.

                  12 Scripts for actions



                  Watermark example http://www.mouseprints.net/old/dpr/WM900x600.jpg

                  1 person found this helpful
                  • 6. Re: Rotate if width smaller than height?
                    phosphorspitter Level 1

                    I  looked at your action descriptions and scripts. You have some good stuff in there.

                    • 7. Re: Rotate if width smaller than height?
                      JJMack Most Valuable Participant

                      Thank You enjoy....