0

My client needs multiple crops for a large group of images but keeps changing the guidelines. Since I need to keep working on the files, I'm hoping to import the guidelines into each file from a single file so that I can use them to batch process at the end. The following script seems to be as close to what I need as I've found but it crashes at line 6:

file = app.openDialog();//opens dialog,choose one image

if(file[0]){ //if you have chosen an image
   app.load(file[0]); //load it into documents
   backFile= app.activeDocument; //prepare your image layer as active document
   backFile.resizeImage(width,height); //resize image into given size i.e 640x480
   backFile.selection.selectAll();
   backFile.selection.copy(); //copy image into clipboard
   backFile.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes
   doc.paste(); //paste selection into your document
   doc.layers[0].name = "BackgroundImage"; //set your layer's name
}

Any help would greatly be appreciated!

1 Answers1

1

There are some variables that haven't been set: like doc, width and height. It'll work if in the beginning you'll add

var width = 640;
var height= 480;
var doc = activeDocument;

But I'm not sure it's what you'll looking for because this script resizes the image that it opens and then pastes this resized image to 1 opened document. If you need to paste 1 image to all the documents you have I'd do something line that:

var f = File.openDialog ();

if (f) {
    backFile= app.open(f);
    backFile.selection.selectAll();
    backFile.selection.copy(); //copy image into clipboard
    backFile.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes

for (i=0; i<documents.length; i++) {
        activeDocument = documents[i];
        activeDocument.paste();
    }
}
Sergey Kritskiy
  • 2,199
  • 2
  • 15
  • 20