5 Replies Latest reply on Jun 7, 2011 3:02 PM by woodwizer

    Batch Increase Canvas based on each image's aspect ratio

    woodwizer Level 1

      Hi

       

      I'm new to scripting, so expect dumb questions

       

      I need to take 1900 images, make them square by increasing the canvas of each image, then convert them to 600x600px

       

      The thing that's stumping me is that each of the source images has a different size\aspect ratio

       

      Is this possible?

       

      TIA

        • 1. Re: Batch Increase Canvas based on each image's aspect ratio
          c.pfaffenbichler Level 9

          I suppose you could even Action that with File > Automate > Fit Image and then use Canvas Size.

           

          But as for a Scripting solution you could just use a conditional clause:

           

          #target photoshop
          var myDocument = app.activeDocument;
          var width = myDocument.width;
          var height = myDocument.height;
          if (width > height) {
               myDocument.resizeCanvas (width, width)
               }
          else {
               myDocument.resizeCanvas (height, height)
               };
          myDocument.resizeImage (new UnitValue(600, "px"), new UnitValue(600, "px"), undefined, ResampleMethod.BICUBIC);
          
          • 2. Re: Batch Increase Canvas based on each image's aspect ratio
            woodwizer Level 1

            Thanks very much for taking the time to reply to my question.  Your script worked perfectly, impressive stuff!!!

             

            Just one more thing.  I can't now work out how to get it to do it over 1900+ files in one operation.  I'm googling but everything seems to be specifically about actions. Am I close?

             

            Any help most apprecieated.

             

            Thanks

            • 3. Re: Batch Increase Canvas based on each image's aspect ratio
              woodwizer Level 1

              So more Googling and I think I have found the solution.  By using the script as part of a Batch Action I can select the folder and have it save and close the images.  This has worked well on my test folder.

               

              One last question.  Sometimes the originl file has been cropped quite harshly in one or either direction.  For example:

               

              ae_wcr1000haken_497475_z_01a.jpg

               

              It doesn't shot very well on this background, but each side could do with 2-5px padding to make it look better.  This can happen in the other axis also.  Is there something we can do to add padding to the whichever direction is not having it's canvas enlarged?

               

              I hope that makes sense.

               

              Thanks again, this has saved many hours.

              • 4. Re: Batch Increase Canvas based on each image's aspect ratio
                Muppet Mark-QAl63s Level 4

                Did you try the first suggestion? With the script you could replace the two values of 600 with 590. Then in your action after this include a canvas size increasing it 600 adding white a pad of 5 pix all around. The same goes for using 'Fit Image' in your action or fit image as part of the 'Image processor' script…

                1 person found this helpful
                • 5. Re: Batch Increase Canvas based on each image's aspect ratio
                  woodwizer Level 1

                  Thanks.  I adjusted the script as you suggested.

                   

                  I was willing to try it any way that got the job done.   It's just I didn't know how to use the Fit Image function and the script worked.

                   

                  Thanks all who helped.