3 Replies Latest reply on Jun 18, 2011 6:34 AM by hiltoncampbell

    Script that rotates a PNG in Photoshop?

    hiltoncampbell Level 1

      I have the following Photoshop ExtendScript (.jsx) script which rotates the image canvas, but doesn't rotate the contents:

       

      #target photoshop

      var doc = app.open(...);       // open the .png file if (doc.width > doc.height) {  // check if this document is landscape   doc.rotateCanvas(90);        // rotate the canvas to portrait   // but how to rotate the contents? }

      I would like to rotate the entire image, contents included. I've  tried also rotating all the document's layers, and art layers, but  nothing works.

        • 1. Re: Script that rotates a PNG in Photoshop?
          markerline Level 4

          Well, "rotateCanvas" is the right method to use according to the CS5

          JavaScript Reference for Photoshop.

           

          I think you might have to select the region first using "activeLayer" or something to that effect.  I'm not very well versed in Javascript at all but I have a resource guide and the Reference that I looked at for this information.  I couldn't zero in on the exact method or syntax to use but I hope it will give you a push in the right direction.

          • 2. Re: Script that rotates a PNG in Photoshop?
            JJMack Most Valuable Participant

            hiltoncampbell wrote:

             

             

             

            #target photoshop

            var doc = app.open(...);       // open the .png file if (doc.width > doc.height) {  // check if this document is landscape   doc.rotateCanvas(90);        // rotate the canvas to portrait   // but how to rotate the contents? }

            While the code look good it may not work??? You see it does not insure what ruler units is.   So if your ruler units were set to something like persent the if statement would read 

            if ( 100% is greater then 100% )  rotate

            I have a script like that RotatePortrait.jsx  to rotate portrait to landscape looks like this

             

            /*

            <javascriptresource>

            <about>$$$/JavaScripts/RotatePortrait/About=JJMack's Rotate Portrait.^r^rCopyright 2009 Mouseprints.^r^rScript utility for action.^rNOTE:Rotate Portrait to Landscape!</about>

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

            </javascriptresource>

            */

            Rotate();

             

            function Rotate() {

             

            // validate that a document is open

            if (documents.length < 1) {

            alert("No Open Document!");

            return;

            }

            var orig_ruler_units = app.preferences.rulerUnits;

            app.preferences.rulerUnits = Units.PIXELS;

            // Rotate portrait to landscape orientation

            if (activeDocument.height > activeDocument.width) activeDocument.rotateCanvas(90);

             

            // Reset units to original settings

            app.preferences.rulerUnits = orig_ruler_units;

            }

            • 3. Re: Script that rotates a PNG in Photoshop?
              hiltoncampbell Level 1

              So... uh... yeah. If you want to  rotate a PNG in Photoshop, the original script would be the way to do it.  Code not shown there might cause it do something different, preventing the rotate from succeeding :).