我需要更正此 photoshop 脚本。
我可以打开 csv 文件,但它无法将图层上的图像与 csv 文件上的图像(我使用的路径)交换出来。
可以通过使用 photoshop 变量在没有脚本的情况下实现,但是我想换出很多文件并且不能来回单击和重复任务。
`// Open the CSV file and parse its content
var csvFile = File.openDialog("Select CSV file", "*.csv");
csvFile.open("r");
var csvContent = csvFile.read();
csvFile.close();
var csvData = csvContent.split("\n");
// Loop through the CSV data and replace images on each layer in Photoshop
for (var i = 1; i < csvData.length; i++) {
var rowData = csvData[i].split(",");
// Open the image file
var imageFile = new File(rowData[0]);
var docRef = app.open(imageFile);
// Loop through each layer and replace the image
for (var j = 1; j <= docRef.layers.length; j++) {
var layer = docRef.layers[j - 1];
// Check if the layer is a image layer
if (layer.kind == LayerKind.NORMAL && layer.bounds.toString() != "[0,0,0,0]") {
// Replace the image layer with the new image file
var imageFilePath = rowData[j];
var newLayer = docRef.artLayers.add();
newLayer.move(layer, ElementPlacement.PLACEBEFORE);
newLayer.name = layer.name;`your text`
newLayer.kind = LayerKind.NORMAL;
var imageFileRef = new File(imageFilePath);
app.activeDocument.activeLayer = newLayer;
app.load(new File(imageFilePath));
docRef.selection.selectAll();
docRef.selection.copy();
docRef.selection.deselect();
app.activeDocument.paste();
layer.remove();
}
}
// Save the modified image file
var saveOptions = new JPEGSaveOptions();
saveOptions.quality = 12;
var newFilePath = rowData[0].replace(".jpg", "_modified.jpg");
docRef.saveAs(new File(newFilePath), saveOptions, true, Extension.LOWERCASE);
docRef.close(SaveOptions.DONOTSAVECHANGES);
}
alert("Done!");`