8 Replies Latest reply on Jul 19, 2011 6:46 PM by Trickycad2

    Crop & Straighten Script Enhancement

    Trickycad2 Level 1

      As part of my workflow which typically processes 1500 or more images overnight I use the Crop & Straighten script included with Photoshop.

      The script works well most of the time, but seems to randomly select small chunks of images which are saved and need to be deleted.

       

      I would like to use a script to tell Photoshop to close images under a certain pixel dimension/file size, so I can weed the image fragments out before they are saved. I have tried modifying other scripts and writing my own, but I am not a programmer and am getting nowhere.

       

      Wondering whether anyone would be able to help.


      Thanks in advance!

        • 1. Re: Crop & Straighten Script Enhancement
          c.pfaffenbichler Level 9

          Have you automated the saving-process?

          If not below Script could also be adapted to save all those images who are not below the set measurements.

           

          Anyway, something like this could be used to close images below certain widths and heights without saving:

           

          // close files below either certain width or height in pixels;

          // use it at your own risk;

          #target photoshop

          var theDocs = app.documents;

          var originalRulerUnits = app.preferences.rulerUnits;

          app.preferences.rulerUnits = Units.PIXELS;

          for (var m = theDocs.length - 1; m >= 0; m--) {

          var theWidth = theDocs[m].width;

          var theHeight = theDocs[m].height;

          // for closing files below certain width and height change || to &&;

          if (theWidth < 1000 || theHeight < 1000) {

          theDocs[m].close(SaveOptions.DONOTSAVECHANGES)

          }

          };

          app.preferences.rulerUnits = originalRulerUnits;

          • 2. Re: Crop & Straighten Script Enhancement
            Trickycad2 Level 1

            Works like a charm- added this just after the crop & straighten and it hasn't missed one yet.

             

            Now if we could just get Adobe to add proper conditional actions/scripting..

             

            Thanks!

            • 3. Re: Crop & Straighten Script Enhancement
              c.pfaffenbichler Level 9
              Now if we could just get Adobe to add proper conditional actions/scripting..

              Scripts do offer the capability to handle conditionals, Actions in contrast lack such capabilities but are extremely easy to use.

              So it’s a trade-off: make do with Actions or look into Scripting, which admittedly can be a bit daunting when one has no JavaScript-experience (or VB- or AppleScript-).

              • 4. Re: Crop & Straighten Script Enhancement
                c.pfaffenbichler Level 9

                Just to make sure: The saving of the resulting files is also automated?

                • 5. Re: Crop & Straighten Script Enhancement
                  Trickycad2 Level 1

                  The save step is automated.

                  I have identified a new issue since running the batch twice with the script you provided though.

                   

                  Here is an overview of the daily processing:

                   

                  Action 1:

                  Crop & Straighten

                  Script to close images under certain pixel dimension without saving (thanks again)

                  Run batch using Action 2 on open files (convoluted I know but it works)

                   

                  Action 2:

                  Levels

                  Sharpen

                  Place watermark

                  Flatten

                  Close / saving yes

                   

                  This works great but I end up with a copy of the original uncropped image and the cropped image.

                  Don't want to impose, but is there any way to compare the file sizes and close the larger (uncropped) image.

                   

                  Thanks.

                  • 6. Re: Crop & Straighten Script Enhancement
                    c.pfaffenbichler Level 9

                    Well, quite frankly you might want to look into Scripting the whole 

                    thing.

                     

                    Anyway, this might work – it just defines the active document before 

                    Crop and Straighten and closes it after that and before doing the size-

                    comparisons.

                     

                    // close files below either certain width or height in pixels;

                    // use it at your own risk;

                    #target photoshop

                    var theDocument = app.activeDocument

                    // crop and straighten;

                    var idCropPhotosAutozerozerozeroone = 

                    stringIDToTypeID( "CropPhotosAuto0001" );

                    executeAction( idCropPhotosAutozerozerozeroone, undefined, 

                    DialogModes.ALL );

                    // close the original without saving;

                    theDocument.close(SaveOptions.DONOTSAVECHANGES);

                    // close any open images below sizes;

                    var theDocs = app.documents;

                    var originalRulerUnits = app.preferences.rulerUnits;

                    app.preferences.rulerUnits = Units.PIXELS;

                    // psd options;

                    psdOpts = new PhotoshopSaveOptions();

                    psdOpts.embedColorProfile = true;

                    psdOpts.alphaChannels = true;

                    psdOpts.layers = true;

                    psdOpts.spotColors = true;

                    // iterate through open files;

                    for (var m = theDocs.length - 1; m >= 0; m--) {

                         var theDoc = theDocs[m];

                         app.activeDocument = theDoc;

                         var theWidth = theDoc.width;

                         var theHeight = theDoc.height;

                    // for closing files below certain width and height change || to &&;

                         if (theWidth < 750 || theHeight < 750) {

                              theDoc.close(SaveOptions.DONOTSAVECHANGES)

                              }

                         else {}

                         };

                    // reset;

                    app.preferences.rulerUnits = originalRulerUnits;

                    1 person found this helpful
                    • 7. Re: Crop & Straighten Script Enhancement
                      Trickycad2 Level 1

                      Thanks again for everything- the script works perfectly!!

                      I will definitely be reading up on scripting so I can build my own.

                       

                      FYI- anyone wanting to use this..

                      The line below has a extra space in SaveOptions which must be removed before using.

                       

                      theDoc.close(SaveOpt ions.DONOTSAVECHANGES)

                      • 8. Re: Crop & Straighten Script Enhancement
                        Trickycad2 Level 1

                        Hi again.. this script works great but sometimes Photoshop does not detect an image large enough so the script closes all of the files. The problem with this is that the action stops and says The command "Save" is not available. Obviously this is because there are no images to save. This kills the action.

                         

                        Would anybody be able to add a step to this so that the script checks to see that there is an image open before going to the close original step:

                         

                        // close the original without saving;

                         

                        theDocument.close(SaveOptions.DONOTSAVECHANGES);

                         

                        So it would do the crop, then close open files below certain size, then only close the original document if there is another file open, and if there are no other files open do nothing else?

                         

                        Any help would be greatly appreciated!!