我需要从给定的psd中将数百个图层保存为jpg文件。 Leyers分为几组,每组的名称应作为jpg文件中的前缀进行比较。
组别1 | layer1的 | 二层 | 三层
组2 | layer1的 | 二层
我需要这样的东西:
组别1-layer1.jpg 组别1 - layer2.jpg 组别1 - layer3.jpg 第2组,layer1.jpg 组2-layer2.jpg
我发现许多.jsx脚本合并和导出组但根据我的需要找不到任何东西。有谁知道这是怎么做到的吗? 谢谢 EMA
答案 0 :(得分:1)
试试这段代码。
#target photoshop
//$.level = 2;
/*
* Script by Loginoff Nick (nloginoff (at) gmail dot com)
* Script export layers to files adding group-name as prefix or create folders like a groups
* Function translite - replac a russian words to english.
* Photoshop CS5
* 04.02.2014
*
*/
var LONG_NAMES = 0; // Save Long Names - Folder_SubFolder_Layer or save only "Layer"
var CREATE_FOLDERS = 1; // Create Hierarchy Folders. Warning if this 0 and LONG_NAMES = 0, maybe recreate files.
var SEPARATOR = '_'; // Separator for file name
var PREFIX_FILE = '' + SEPARATOR; //
function main(){
if(!documents.length) return;
var doc = activeDocument;
var DocPath = activeDocument.path;
var DocName = translite(doc.name.replace(/\.psd/g,''));
var outFolder = new Folder(DocPath + "/" + DocName + "_layers");
if (!outFolder.exists) {
outFolder.create();
}
scanLayers(doc,outFolder,PREFIX_FILE + DocName);
function scanLayers(el, current_folder, prefix_name) {
for(var a=0;a<el.layers.length;a++) {
var lname = translite(el.layers[a].name);
var file_name = lname;
if ( LONG_NAMES ) {
file_name = prefix_name + SEPARATOR + lname;
}
saveLayer(el.layers[a], file_name, current_folder, false);
// recurstion
if ( el.layers[a].layers && el.layers[a].layers.length > 0 ) {
var new_folder = current_folder;
if ( CREATE_FOLDERS ) {
new_folder = current_folder + "/" + lname;
var destFolder = new Folder(new_folder);
if (!destFolder.exists) {
destFolder.create();
}
}
scanLayers(el.layers[a], new_folder, file_name);
}
}
}
function translite(str){
var arr={'а':'a', 'б':'b', 'в':'v', 'г':'g', 'д':'d', 'е':'e', 'ж':'g', 'з':'z', 'и':'i', 'й':'y', 'к':'k', 'л':'l', 'м':'m', 'н':'n', 'о':'o', 'п':'p', 'р':'r', 'с':'s', 'т':'t', 'у':'u', 'ф':'f', 'ы':'i', 'э':'e', 'А':'A', 'Б':'B', 'В':'V', 'Г':'G', 'Д':'D', 'Е':'E', 'Ж':'G', 'З':'Z', 'И':'I', 'Й':'Y', 'К':'K', 'Л':'L', 'М':'M', 'Н':'N', 'О':'O', 'П':'P', 'Р':'R', 'С':'S', 'Т':'T', 'У':'U', 'Ф':'F', 'Ы':'I', 'Э':'E', 'ё':'yo', 'х':'h', 'ц':'ts', 'ч':'ch', 'ш':'sh', 'щ':'shch', 'ъ':'', 'ь':'', 'ю':'yu', 'я':'ya', 'Ё':'YO', 'Х':'H', 'Ц':'TS', 'Ч':'CH', 'Ш':'SH', 'Щ':'SHCH', 'Ъ':'', 'Ь':'','Ю':'YU', 'Я':'YA'};
var replacer=function(a){return a in arr ? arr[a] : '';};
return str.replace(/[А-яёЁьЬ]/g,replacer).toLowerCase();
}
};
main();
function saveLayer(layer, lname, path, shouldMerge) {
activeDocument.activeLayer = layer;
dupLayers();
if (shouldMerge === undefined || shouldMerge === true) {
activeDocument.mergeVisibleLayers();
}
activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true);
var saveFile= File(path +"/"+lname+'.png');
SavePNG(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
};
function dupLayers() {
var desc143 = new ActionDescriptor();
var ref73 = new ActionReference();
ref73.putClass( charIDToTypeID('Dcmn') );
desc143.putReference( charIDToTypeID('null'), ref73 );
desc143.putString( charIDToTypeID('Nm '), activeDocument.activeLayer.name );
var ref74 = new ActionReference();
ref74.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc143.putReference( charIDToTypeID('Usng'), ref74 );
executeAction( charIDToTypeID('Mk '), desc143, DialogModes.NO );
};
function SavePNG(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);
};