*** 1,9 **** --- 1,40 ---- // Copyright 2007. Adobe Systems, Incorporated. All rights reserved. // This script will export each layer in the document to a separate file. // Written by Naoki Hada // ZStrings and auto layout by Tom Ruark + // + // *************************************************************************** + // *************************************************************************** + // + // THIS SCRIPT HAS BEEN MODIFIED by Leo Davidson + // Modified on 3rd June 2007, from version 1.0.0.8 that comes with PS CS3. + // + // Two things have been added: + // + // 1) Support for saving PNG files. + // + // It is strange that it was left out of the original script. + // + // 2) Fast Mode (Don't remove hidden layers). + // + // There is a new "Fast Mode (Don't remove hidden layers)" checkbox + // which, when turned on, causes the script to export the layers in a much, + // much faster way. + // + // Normally the script duplicates the document for each layer and removes + // all other layers before saving the duplicated document. This means that + // only the desired layer is saved but it also makes the script really + // slow (it runs in O(n^2) time instead of O(n)). Turning on the Fast Mode + // causes the script to hide, but not erase, the unwanted layers. This + // means the resultant files may contain unwanted hidden layers, if + // saving to an image format which supports layers, but if you are + // ultimately just going to flatten and resave each file then this + // doesn't matter and saves you a huge amount of time. + // + // *************************************************************************** + // *************************************************************************** /* @@@BUILDINFO@@@ Export Layers To Files.jsx 1.0.0.8 */ *************** *** 43,56 **** --- 74,90 ---- var strHelpText = localize("$$$/JavaScripts/ExportLayersToFiles/Help=Please specify the format and location for saving each layer as a file."); var strLabelDestination = localize("$$$/JavaScripts/ExportLayersToFiles/Destination=Destination:"); var strButtonBrowse = localize("$$$/JavaScripts/ExportLayersToFiles/Browse=&Browse..."); var strLabelFileNamePrefix = localize("$$$/JavaScripts/ExportLayersToFiles/FileNamePrefix=File Name Prefix:"); var strCheckboxVisibleOnly = localize("$$$/JavaScripts/ExportLayersToFiles/VisibleOnly=&Visible Layers Only"); + var strCheckboxFastAndSimple = localize("$$$/JavaScripts/ExportLayersToFiles/FastAndSimple=&Fast Mode (Don't remove hidden layers)"); var strLabelFileType = localize("$$$/JavaScripts/ExportLayersToFiles/FileType=File Type:"); var strCheckboxIncludeICCProfile = localize("$$$/JavaScripts/ExportLayersToFiles/IncludeICC=&Include ICC Profile"); var strJPEGOptions = localize("$$$/JavaScripts/ExportLayersToFiles/JPEGOptions=JPEG Options:"); var strLabelQuality = localize("$$$/JavaScripts/ExportLayersToFiles/Quality=Quality:"); + var strPNGOptions = localize("$$$/JavaScripts/ExportLayersToFiles/PNGOptions=PNG Options:"); + var strCheckboxInterlaced = localize("$$$/JavaScripts/ExportLayersToFiles/Interlaced=Interlaced"); var strPSDOptions = localize("$$$/JavaScripts/ExportLayersToFiles/PSDOptions=PSD Options:"); var strCheckboxMaximizeCompatibility = localize("$$$/JavaScripts/ExportLayersToFiles/Maximize=&Maximize Compatibility"); var strTIFFOptions = localize("$$$/JavaScripts/ExportLayersToFiles/TIFFOptions=TIFF Options:"); var strLabelImageCompression = localize("$$$/JavaScripts/ExportLayersToFiles/ImageCompression=Image Compression:"); var strNone = localize("$$$/JavaScripts/ExportLayersToFiles/None=None"); *************** *** 77,89 **** // the drop down list indexes for file type var bmpIndex = 0; var jpegIndex = 1; var pdfIndex = 2; ! var psdIndex = 3; ! var targaIndex = 4; ! var tiffIndex = 5; // the drop down list indexes for tiff compression var compNoneIndex = 0; var compLZWIndex = 1; var compZIPIndex = 2; --- 111,124 ---- // the drop down list indexes for file type var bmpIndex = 0; var jpegIndex = 1; var pdfIndex = 2; ! var pngIndex = 3; ! var psdIndex = 4; ! var targaIndex = 5; ! var tiffIndex = 6; // the drop down list indexes for tiff compression var compNoneIndex = 0; var compLZWIndex = 1; var compZIPIndex = 2; *************** *** 258,267 **** --- 293,307 ---- // -- the fifth line in the dialog dlgMain.cbVisible = dlgMain.grpTopLeft.add("checkbox", undefined, strCheckboxVisibleOnly); dlgMain.cbVisible.value = exportInfo.visibleOnly; // -- the sixth line is the panel + dlgMain.cbFastAndSimple = dlgMain.grpTopLeft.add("checkbox", undefined, strCheckboxFastAndSimple); + dlgMain.cbFastAndSimple.value = exportInfo.fastAndSimple; + dlgMain.cbFastAndSimple.alignment = 'left'; + + // -- the seventh line is the panel dlgMain.pnlFileType = dlgMain.grpTopLeft.add("panel", undefined, strLabelFileType); dlgMain.pnlFileType.alignment = 'fill'; // -- now a dropdown list dlgMain.ddFileType = dlgMain.pnlFileType.add("dropdownlist"); *************** *** 269,278 **** --- 309,319 ---- dlgMain.ddFileType.alignment = 'left'; dlgMain.ddFileType.add("item", "BMP"); dlgMain.ddFileType.add("item", "JPEG"); dlgMain.ddFileType.add("item", "PDF"); + dlgMain.ddFileType.add("item", "PNG"); dlgMain.ddFileType.add("item", "PSD"); dlgMain.ddFileType.add("item", "Targa"); dlgMain.ddFileType.add("item", "TIFF"); dlgMain.ddFileType.onChange = function() { *************** *** 284,293 **** --- 325,338 ---- break; case jpegIndex: dlgMain.pnlFileType.pnlOptions.text = strJPEGOptions; dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.show(); break; + case pngIndex: + dlgMain.pnlFileType.pnlOptions.text = strPNGOptions; + dlgMain.pnlFileType.pnlOptions.grpPNGOptions.show(); + break; case tiffIndex: dlgMain.pnlFileType.pnlOptions.text = strTIFFOptions; dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.show(); break; case pdfIndex: *************** *** 328,337 **** --- 373,387 ---- dlgMain.pnlFileType.pnlOptions.grpJPEGOptions = dlgMain.pnlFileType.pnlOptions.add("group"); dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.add("statictext", undefined, strLabelQuality); dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.etQuality = dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.add("edittext", undefined, exportInfo.jpegQuality.toString()); dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.etQuality.preferredSize.width = StrToIntWithDefault( stretQuality, 30 ); + // PNG options + dlgMain.pnlFileType.pnlOptions.grpPNGOptions = dlgMain.pnlFileType.pnlOptions.add("group"); + dlgMain.pnlFileType.pnlOptions.grpPNGOptions.cbInterlaced = dlgMain.pnlFileType.pnlOptions.grpPNGOptions.add("checkbox", undefined, strCheckboxInterlaced); + dlgMain.pnlFileType.pnlOptions.grpPNGOptions.cbInterlaced.value = exportInfo.pngInterlaced; + // TIFF options dlgMain.pnlFileType.pnlOptions.grpTIFFOptions = dlgMain.pnlFileType.pnlOptions.add("group"); dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.orientation = 'column'; dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.add("group"); *************** *** 511,523 **** --- 561,575 ---- // get setting from dialog exportInfo.destination = dlgMain.etDestination.text; exportInfo.fileNamePrefix = dlgMain.etFileNamePrefix.text; exportInfo.visibleOnly = dlgMain.cbVisible.value; + exportInfo.fastAndSimple = dlgMain.cbFastAndSimple.value; exportInfo.fileType = dlgMain.ddFileType.selection.index; exportInfo.icc = dlgMain.cbIcc.value; exportInfo.jpegQuality = dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.etQuality.text; + exportInfo.pngInterlaced = dlgMain.pnlFileType.pnlOptions.grpPNGOptions.cbInterlaced.value; exportInfo.psdMaxComp = dlgMain.pnlFileType.pnlOptions.grpPSDOptions.cbMax.value; index = dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.grpCompression.ddCompression.selection.index; if (index == compNoneIndex) { exportInfo.tiffCompression = TIFFEncoding.NONE; } *************** *** 568,577 **** --- 620,630 ---- // Return: , all panels are now hidden /////////////////////////////////////////////////////////////////////////////// function hideAllFileTypePanel() { dlgMain.pnlFileType.pnlOptions.grpPSDOptions.hide(); dlgMain.pnlFileType.pnlOptions.grpJPEGOptions.hide(); + dlgMain.pnlFileType.pnlOptions.grpPNGOptions.hide(); dlgMain.pnlFileType.pnlOptions.grpTIFFOptions.hide(); dlgMain.pnlFileType.pnlOptions.grpPDFOptions.hide(); dlgMain.pnlFileType.pnlOptions.grpTargaOptions.hide(); dlgMain.pnlFileType.pnlOptions.grpBMPOptions.hide(); } *************** *** 585,597 **** --- 638,652 ---- /////////////////////////////////////////////////////////////////////////////// function initExportInfo(exportInfo) { exportInfo.destination = new String(""); exportInfo.fileNamePrefix = new String("untitled_"); exportInfo.visibleOnly = false; + exportInfo.fastAndSimple = false; exportInfo.fileType = psdIndex; exportInfo.icc = true; exportInfo.jpegQuality = 8; + exportInfo.pngInterlaced = false; exportInfo.psdMaxComp = true; exportInfo.tiffCompression = TIFFEncoding.NONE; exportInfo.tiffJpegQuality = 8; exportInfo.pdfEncoding = PDFEncoding.JPEG; exportInfo.pdfJpegQuality = 8; *************** *** 624,633 **** --- 679,694 ---- jpgSaveOptions = new JPEGSaveOptions(); jpgSaveOptions.embedColorProfile = exportInfo.icc; jpgSaveOptions.quality = exportInfo.jpegQuality; docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE); break; + case pngIndex: + var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".png"); + pngSaveOptions = new PNGSaveOptions(); + pngSaveOptions.interlaced = exportInfo.pngInterlaced; + docRef.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE); + break; case psdIndex: var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".psd"); psdSaveOptions = new PhotoshopSaveOptions(); psdSaveOptions.embedColorProfile = exportInfo.icc; psdSaveOptions.maximizeCompatibility = exportInfo.psdMaxComp; *************** *** 781,805 **** --- 842,873 ---- } } dupObj.artLayers[i].visible = true; var layerName = dupObj.artLayers[i].name; // store layer name before change doc + + if (!exportInfo.fastAndSimple) { var duppedDocumentTmp = dupDocRef.duplicate(); if (psdIndex == exportInfo.fileType) { // PSD: Keep transparency removeAllInvisible(duppedDocumentTmp); } else { // just flatten duppedDocumentTmp.flatten(); } + } var fileNameBody = fileNamePrefix; fileNameBody += "_" + zeroSuppress(i, 4); fileNameBody += "_" + layerName; fileNameBody = fileNameBody.replace(/[:\/\\*\?\"\<\>\|]/g, "_"); // '/\:*?"<>|' -> '_' if (fileNameBody.length > 120) { fileNameBody = fileNameBody.substring(0,120); } + if (exportInfo.fastAndSimple) { + saveFile(dupObj, fileNameBody, exportInfo); + } else { saveFile(duppedDocumentTmp, fileNameBody, exportInfo); duppedDocumentTmp.close(SaveOptions.DONOTSAVECHANGES); + } dupObj.artLayers[i].visible = false; } for( var i = 0; i < dupObj.layerSets.length; i++) { if (exportInfo.visibleOnly) { // visible layer only *************** *** 844,854 **** break; case "number": d.putDouble(k, v); break; default: ! throw( new Error("Unsupported type in objectToDescriptor " + typeof(v) ) ); } } return d; } --- 912,922 ---- break; case "number": d.putDouble(k, v); break; default: ! throw( new Error("Unsupported type in objectToDescriptor " + typeof(v) + " (" + o.reflect.properties[i].toString() + ")" ) ); } } return d; }