JSX导出png和jpg文件会导致Macbook崩溃

时间:2018-03-20 12:51:10

标签: photoshop jsx

大家好,我一直在使用这个脚本,但是每次运行脚本时我的Macbook都会突然崩溃。有谁知道Photoshop是否有任何更新可能会改变JSX文件的行为?或类似的东西?

我在Adobe Photoshop版本中运行脚本:19.0 20171103.r.190 2017/11/03:1143799 x64

请参阅此处的脚本:

function main(){
if(!documents.length) return;
var doc = activeDocument; 
 var oldPath = activeDocument.path;
var theParent = activeDocument.activeLayer.parent;


var outFolder = new Folder(oldPath + "/assets");
if (!outFolder.exists) {
    outFolder.create();
}

scanLayerSets(doc);

function scanLayerSets(el) {
    // find layer groups
    for(var a=0;a<el.layerSets.length;a++){
        var lname = el.layerSets[a].name;
         var rararara = lname.replace(".png",'')+"-"+el.layerSets.parent.name.toLowerCase()+".png";
          var rarararaTwo = lname.replace(".jpg",'')+"-"+el.layerSets.parent.name.toLowerCase()+".jpg";
        if (lname.substr(-4) == ".png") {
            saveLayerPNG(el.layers.getByName(lname), rararara, oldPath, true);
        } 
        else if (lname.substr(-4) == ".jpg") {
            saveLayer(el.layers.getByName(lname), rarararaTwo, oldPath, true);
        }else {
            // recursive
            scanLayerSets(el.layerSets[a]);
        }
    }

        // find plain layers in current group whose names end with .png
    for(var j=0; j<el.artLayers.length; j++) {
        var name = el.artLayers[j].name;
         var rararara = name.replace(".png",'')+"-"+el.layerSets.parent.name.toLowerCase()+".png";
         var rarararaThree = name.replace(".jpg",'')+"-"+el.layerSets.parent.name.toLowerCase()+".jpg";
       if (name.substr(-4) == ".png") {
           saveLayerPNG(el.layers.getByName(name), rararara, oldPath, false);
        }
    else if (name.substr(-4) == ".jpg") {
           saveLayer(el.layers.getByName(name), rarararaThree, oldPath, false);
        }
    }


}

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 +"/assets/"+lname);
    //SavePNG(saveFile);
    SaveForWeb(saveFile,60); //change to 60 for 60%      
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

function saveLayerPNG(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 +"/assets/"+lname);
    SavePNG(saveFile);
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

};

main();

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); 
}

function SaveForWeb(saveFile,jpegQuality) {  
var sfwOptions = new ExportOptionsSaveForWeb();   
   sfwOptions.format = SaveDocumentType.JPEG;   
   sfwOptions.includeProfile = false;   
   sfwOptions.interlaced = 0;   
   sfwOptions.optimized = true;   
   sfwOptions.quality = jpegQuality; //0-100   
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);  
}  

0 个答案:

没有答案