How can I crop by x,y,width,height all images in a folder, resize them, then save them?

StackOverflow https://stackoverflow.com/questions/21765086

  •  11-10-2022
  •  | 
  •  

質問

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.

役に立ちましたか?

解決

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

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top