分享三个photoshop小脚本(JavaScript)

来源:互联网 发布:php面向对象编程 pdf 编辑:程序博客网 时间:2024/04/30 10:47

打包下载地址: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-12activeDocument.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 imagevar 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.layerfunction 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 typefunction 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》

0 0
原创粉丝点击