#target photoshop function main(){ var doc = app.activeDocument; var psdPath = app.activeDocument.path; var outFolderName="pngExport"; var twosize=true; var outFolder = new Folder(psdPath + "/"+outFolderName); if (!outFolder.exists) { outFolder.create(); } var lname = doc.activeLayer.name; saveLayer(doc.activeLayer, lname, psdPath, false); function saveLayer(layer, lname, path, shouldMerge) { dupLayers(); if (shouldMerge === undefined || shouldMerge === true) { activeDocument.mergeVisibleLayers(); } activeDocument.trim(TrimType.TRANSPARENT,true,true,true,true); var saveFile= File(path +"/"+outFolderName+"/"+lname+"@2x.png"); SavePNG(saveFile); if(twosize){ var re_width=activeDocument.width*0.5; var re_height=activeDocument.height*0.5; activeDocument.resizeImage(re_width,re_height); var saveFilesmall= File(path +"/"+outFolderName+"/"+lname+".png"); SavePNG(saveFilesmall); } app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); } } if(documents.length && !activeDocument.activeLayer.isBackgroundLayer){ try { main(); } catch (e) { alert(e); } } function dupLayers() { var descac = new ActionDescriptor(); var refac1 = new ActionReference(); refac1.putClass( charIDToTypeID('Dcmn') ); descac.putReference( charIDToTypeID('null'), refac1 ); descac.putString( charIDToTypeID('Nm '), activeDocument.activeLayer.name ); var refac2 = new ActionReference(); refac2.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); descac.putReference( charIDToTypeID('Usng'), refac2 ); executeAction( charIDToTypeID('Mk '), descac, 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); }
photoshop脚本切图方法(习惯快捷键的朋友可以用,很方便)
原文地址:http://blog.csdn.net/rainlesvio/article/details/44922497