天天看點

分享三個photoshop小腳本(JavaScript)

打包下載下傳位址:http://u.163.com/nye9b3Q3  提取碼: aWz10Oig

1、layerRename.jsx 圖層批量重命名

//批量修改圖層名稱,輸入新名稱字首
var doc =  app.activeDocument;
var newLayerName = prompt ("請輸入新名稱的字首:" , doc.layers[0].name, "層命名工具");
//alert (newLayerName);
if (newLayerName != null) {
	for (i=0; i<doc.layers.length;i++)
	{
		doc.layers[i].name = newLayerName+(doc.layers.length-i);
		//隐藏圖層
		//doc.layers[i].visible = false;
		//doc.layers[i].name = newLayerName+"_"+(i+1);
	}
}
           

2、exportLayer.jsx 單獨導出所有層,default導出png格式

//批量導圖(png/jpg)工具,指定儲存路徑
var doc =  app.activeDocument;
var savePath = prompt ("請輸入儲存路徑:" , doc.path, "批量導出圖工具");
//alert (newLayerName);
function SavePNG(saveFile, compressionValue) {
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.compression = compressionValue;
pngSaveOptions.interlaced = false;
activeDocument.saveAs(saveFile, pngSaveOptions, true,Extension.LOWERCASE);
}

/*
function SaveJPEG(saveFile, jpegQuality) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
*/

if (savePath != null) {
	for (i=0; i<doc.layers.length;i++)
    {
        app.activeDocument.layers[i].visible = true;
        saveFile = new File(savePath+'/'+doc.layers[i].name+ '.png');
        SavePNG(saveFile, 9);
		//SaveJPEG(saveFile, 10);
        app.activeDocument.layers[i].visible = false;
    }
}
           

3、importSequenceAsLayer.jsx 批量導入序列并自動配置設定到每個圖層

var seq_path = prompt ("請輸入圖檔所在檔案目錄:" , "C:\\Users\\Administrator\\Desktop", "批量導入圖檔到圖層");
var sourceFolder = Folder(seq_path);
var seq_file = sourceFolder.getFiles("*.png");

// import frist image
var currentDoc = open(new File(seq_file[0]));
currentDoc.layers[0].name = currentDoc.name;

for (var i = 1;i < seq_file.length; i++) {
	fileToLayer(seq_file[i], currentDoc);
}
saveDoc_psd(currentDoc);

//open file,rename layer, copy layer to newDoc.layer
function fileToLayer(input_file_path, newDoc) {
var file_path = new File(input_file_path);
var doc_temp = open (file_path);
doc_temp.layers[0].name = doc_temp.name;
doc_temp.layers[0].duplicate(newDoc, ElementPlacement.INSIDE);
doc_temp.close (SaveOptions.DONOTSAVECHANGES);
}

//save document psd type
function saveDoc_psd(currentDoc) {
saveFilePath = new File(currentDoc.path+'/'+currentDoc.name+ '.psd');
psdSaveOptions = new PhotoshopSaveOptions();
currentDoc.saveAs(saveFilePath,psdSaveOptions , true, Extension.LOWERCASE);
}
           

鑒于這方面資料少,本人願意共享一些自己的腳本。

參考資料《Photoshop-CS6-JavaScript-Ref》、《JavaScript Tools Guide CS6》

繼續閱讀