Copy link to clipboard
Copied
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
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, Resam
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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…
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now