Skip to main content
Participant
June 6, 2011
Answered

Batch Increase Canvas based on each image's aspect ratio

  • June 6, 2011
  • 2 replies
  • 1875 views

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

This topic has been closed for replies.
Correct answer c.pfaffenbichler

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 replies

woodwizerAuthor
Participant
June 7, 2011

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:

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.

Muppet_Mark-QAl63s
Inspiring
June 7, 2011

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…

woodwizerAuthor
Participant
June 7, 2011

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.

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
June 7, 2011

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);

woodwizerAuthor
Participant
June 7, 2011

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