Question

I am new to Photoshop scripting, but no stranger to Javascript.

I have a folder of images of 1024*1024 that are frames of an animation in a 3d program.

There is only an area at x=54, y=12, width=300, height=234 for all the frames.

After the crop I would like them to be scaled at 65% or whatever I want.

Alternatively I would like the source image to be scaled, the image moved x / y coordinates at 65% reduction so that the outside pixels don't make it in the final product.

There are no psds to speak of, I assume the script would create a blank psd and most likely have it recycled for the batch crop/resize.

Was it helpful?

Solution

Try something along these lines for the cropping and resizing. You can also copy all the images into a single PSD before you save if that is what you're after, but this sample just saves over the original document. For more info check out your Photoshop JavaScript Reference pdf in your Photoshop install directory.

var dir = new Folder('/c/temp')
var files = dir.getFiles("*.psd");  //change for whatever file type you have

for (var i = 0; i < files.length; i++) {
    var doc = app.open(files[i]);
    var bounds = [54, 12, 354, 246];
    doc.crop(bounds);

    //do the math to figure out how big you want it after resize
    doc.resizeImage(newWidth, newHeight);

    //note this is saving over the original!!!!
    doc.close(SaveOptions.SAVECHANGES)
}

OTHER TIPS

why not just record the action in photoshop???

open the first file and create a new action. proceed to trim the canvas as needed with either the crop tool or canvas resize. run the action as a batch process on the folder as needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top