4 Replies Latest reply on Dec 30, 2010 8:19 PM by JJMack

    need help with a basic script to resize image then resize the canvas

    bfox2718 Level 1

      I am new to photoshop scripting, and have come across a need to force an image to be 8"x10" at 300dpi (whether it is vertical or horizontal)

       

      I need to maintain the correct orientation in the file, so an Action will not work, I believe I have to implement a script to accomplish this.

       

      I have the below script so far, but I am not certain of how to input the variables / paramters

       

      doc = app.activeDocument;
      if (doc.height > doc.width) doc.resizeImage("2400 pixels","3600 pixels", "300", "BICUBIC");
      if (doc.height > doc.width) doc.resizeCanvas("2400 pixels","3000 pixels", "MIDDLECENTER");

      if (doc.height < doc.width) doc.resizeImage("3600 pixels","2400 pixels",300,"BICUBIC");
      if (doc.height < doc.width) doc.resizeCanvas(3000,2400,"MIDDLECENTER");

       

      When I run this script, I get the following error:

       

      Error 1245: Illegal argument - argument 4

      - Enumerated value expected

      Line: 5

      if (doc.height < doc.width) doc.resizeImage("3600 pixels","2400 pixels",300,"BICUBIC");

       

      error.jpg

       

      The fact that its failing on lien 5 lets nme know that I have the "If" portions of my script correct, I just dont know how to accomplish the functions correctly.

      Any help would be appreciated!

       

       

      Thanks,

      Brian

        • 1. Re: need help with a basic script to resize image then resize the canvas
          Paul Riggott Level 6

          This should be close...

          #target photoshop
          main();
          function main(){
          if(!documents.length) return;
          doc = app.activeDocument;
          if(doc.height > doc.width){
           doc.resizeImage(UnitValue(3600, "px"), undefined, 300, ResampleMethod.BICUBIC);
           doc.resizeCanvas(new UnitValue(2400,'px'),new UnitValue(3000,'px'), AnchorPosition.MIDDLECENTER);
           }else{
                doc.resizeImage(undefined, UnitValue(3600, "px"), 300, ResampleMethod.BICUBIC);
                doc.resizeCanvas(new UnitValue(3000,'px'),new UnitValue(2400,'px'), AnchorPosition.MIDDLECENTER);
               }
          }
          
          1 person found this helpful
          • 2. Re: need help with a basic script to resize image then resize the canvas
            bfox2718 Level 1

            Paul,

             

            thank you so much!  That seemed to get VERY Close... below is my final adjusted script:

             


            #target photoshop
            main();
            function main(){
            if(!documents.length) return;
            doc = app.activeDocument;

             

            if(doc.height > doc.width){
            doc.resizeImage(UnitValue(2400, "px"), undefined, 300, ResampleMethod.BICUBIC);
            doc.resizeCanvas(new UnitValue(2400,'px'),new UnitValue(3000,'px'), AnchorPosition.MIDDLECENTER);

             

             

             

            }else{
                  doc.resizeImage(undefined, UnitValue(2400, "px"), 300, ResampleMethod.BICUBIC);
                  doc.resizeCanvas(new UnitValue(3000,'px'),new UnitValue(2400,'px'), AnchorPosition.MIDDLECENTER);
                 }
            }

            • 4. Re: need help with a basic script to resize image then resize the canvas
              JJMack Most Valuable Participant

              I know I'm late here but it seems to me your trying to automate a 8"x10 or 10"x8 300DPI  print.

               

              To do that you must first crop your image to a 4:5 aspect ratio to prevent distortion unless your shooting with a 4" by 5" camera.   I wrote a Plugin script a couple years ago that could help you do a centered crop.  You could do the whole process by recording a simple Photoshop action that uses two  Plugin Scripts only four steps would be needed.

               

              Step 1 Menu File>Automate>AspectRatioSelection  (My script based of Adobe Fit Image Plugin script) Set 4:5 Aspect ratio, center,  Rectangle, Replace, no feather. Llike Fit Image this script woks on both Landscape and Portrait images. The Selection will be correct for the images orientation.

               

              Step 2 Menu Image>Crop

               

              Step 3 Menu File>Automate>Fit Image set 3000 PX height and 3000 PX width the Image will be Resample so its longest side will be 3000 pixels.  Adobe Fit Image Plugin Script always uses BICUBIC resampling.  I have a modified version of Fit Image  that uses Bicubic Sharper whebndownsizing and BicubicSmoother when up sizing.

               

              Step 4 Menu Image>Size un check resample set resolution to 300 DPI.

               

              When you play the actions the Script Dialogs will not be displayed and the setting use when you recorded the action will ne used.

               

              The Plugin Script are included in my crafting actions package:

               

              http://www.mouseprints.net/old/dpr/JJMacksCraftingActions.zip

              Contains:

              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

               

               

              My other free Photoshop downloads cam be found here: http://www.mouseprints.net/Photoshop.html

              1 person found this helpful