尝试在Photoshop JSX脚本中将画布大小导出为文件名

时间:2016-05-11 20:11:32

标签: javascript photoshop jsx

我不是程序员,而是试图为Photoshop编写脚本。下面是我找到的东西,但它只是递增文件“1.p​​ng,2.png等...”我想命名导出的文件,“documentName_canvasWidth_canvasHeight_incrementedNumber.png”

 function sfwPNG24(saveFile){
 var pngOpts = new ExportOptionsSaveForWeb;
 pngOpts.format = SaveDocumentType.PNG
 pngOpts.PNG8 = false;
 pngOpts.transparency = true;
 pngOpts.interlaced = false;
 pngOpts.quality = 100;
 activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
 }

 /*
 Incrementing a number inside a text layer then Saving it in PNG
 */

 var layer = activeDocument.layers[0];

 if (layer.kind == 'LayerKind.TEXT') {
 for (var i=1; i < 7; i++) {
 layer.textItem.contents = i.toString();
 sfwPNG24( 'filepathgoeshere'+ i +'.png');
 };
 };

1 个答案:

答案 0 :(得分:0)

将这些更改添加到代码的第二部分:

var layer = activeDocument.layers[0];

// documentName_canvasWidth_canvasHeight_incrementedNumber.png

var srcDoc = app.activeDocument;

// get width and height
var W = srcDoc.width.value;
var H = srcDoc.height.value;

// get document name
var fn = srcDoc.name;


 if (layer.kind == 'LayerKind.TEXT')
{
 for (var i=1; i < 7; i++)
{
    layer.textItem.contents = i.toString();
 sfwPNG24( 'filepathgoeshere'+ W + "_" + H + "_" + i +'.png')
}
}