Copy link to clipboard
Copied
I'm on PS CC on MacOX.
Hello all, I am trying to find some batching (either actions or script) that will allow a images to be resized to a canvas, fill the canvas and maintain aspect ratio.
My images are all various sizes, but are close in size to the canvas. Some are more narrow or shorter than the canvas and I'd like the image to fill it so there's no white/transparent space. If the image is bigger in all ways, it would be good if the image could shrink to fill the canvas (but not as pressing as the first requirement). I realize I can cmd-T and drag the images to size manually but I have hundreds to do. Cropping is perfectly fine and if there's a way to then also batch center the image within the canvas, that would be great.
I will still have to go through and manually inspect each one to make sure I didn't accidentally crop someone's face or something, but automating the initial process will still save me a ton of time.
I've been messing with this issue for a couple of days so if I'm not explaining it in a way that a sane person can understand, please ask questions so I can clarify.
Thanks! 3_dots
Try this script:
// https://forums.adobe.com/thread/1968642
// https://forums.adobe.com/message/8022190#8022190
#target photoshop
var oldPref = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var iLayer = doc.activeLayer;
doc.activeLayer = iLayer;
var scale = Math.max(doc.width/(iLayer.bounds[2]-iLayer.bounds[0]),doc.height/(iLayer.bounds[3]-iLayer.bounds[1])); // Optionally change Math.max to Math.min to fit canvas short s
...
Copy link to clipboard
Copied
Try this script:
// https://forums.adobe.com/thread/1968642
// https://forums.adobe.com/message/8022190#8022190
#target photoshop
var oldPref = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var iLayer = doc.activeLayer;
doc.activeLayer = iLayer;
var scale = Math.max(doc.width/(iLayer.bounds[2]-iLayer.bounds[0]),doc.height/(iLayer.bounds[3]-iLayer.bounds[1])); // Optionally change Math.max to Math.min to fit canvas short side
iLayer.resize (scale*100,scale*100);
iLayer.translate(doc.width/2-(iLayer.bounds[0]+iLayer.bounds[2])/2,doc.height/2-(iLayer.bounds[1]+iLayer.bounds[3])/2);
app.preferences.rulerUnits = oldPref;
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
Awesome, will give it a try now. Anything I need to know? Will it parse through all the image layers automatically? Do they need to be smart objects or anything else? Thanks!
Copy link to clipboard
Copied
NVM my previous reply. I got it! Paired it with this solution for iterating through layers, unless you have a difference solution that I'm not seeing?
Thanks!!!
3dots
Copy link to clipboard
Copied
If anyone else comes across this solution, here's what I did:
Copy link to clipboard
Copied
Glad this helped, I didn't understand that you were trying to process multi-layer images.
Copy link to clipboard
Copied
Thanks for posting your step-by-step solution – it really helped me today.
Copy link to clipboard
Copied
Thank you very much for the solution, it helped a lot
Copy link to clipboard
Copied
Thank you, you saved the day, I downloaded both the scripts and all works fine, guys when you go to download the script from step 2 take the longer script at the bottom of the page
Copy link to clipboard
Copied
Another scripted option here:
* Maintain Aspect Ratio
* Fill Canvas (may crop)
* Fit to Canvas (may distort)