Adding a photo from a file as a clipping mask JavaScript
Hello!
I have a .psd file which has a rectangle (layername=rec). I don't understand how to modify my script so that the inserted image is centered in the rectangle and inserted as a clipping mask.
Below is my script for adding a photo from a folder to the active layer of my document. I'm sorry, I'm quite new to working with scripts in Photoshop. Thank you!
And as each photo is added, the "No Embedded Profile" dialog box pops up, waiting for me to choose a treatment. How can I set the default value in the script so that this window does not appear?
#target photoshop
app.bringToFront();
myDocName=app.activeDocument.name
function getFolder() {
return Folder.selectDialog('Select Folder Import:', Folder('~'));
}
function importFolderAsLayers(selectedFolder) {
if (selectedFolder) {
var docList = selectedFolder.getFiles();
for (var i = 0; i < docList.length; i++) {
open(docList[i]); // open documents from list
var docRef = app.activeDocument;
var docName = docRef.name; // get document name
if (docRef.layers.length > 1) { // merge multilayer documents
docRef.artLayers.add();
docRef.mergeVisibleLayers();
}
docRef.changeMode(ChangeMode.RGB);
// duplicate the layer into the new document
docRef.activeLayer.name='img'
docRef.activeLayer.duplicate(documents[myDocName],ElementPlacement.PLACEATBEGINNING);
docRef.close(SaveOptions.DONOTSAVECHANGES);
// name duplicate layer using the original document name
}
}
}
importFolderAsLayers(getFolder())