Photoshop est programmable en JS depuis la version 6 au moins (la 5 doît l'être aussi en VB)
Je crois me souvenir (je peux me tromper) qu'il y a quelque part un menu permettant de charger un script JS, regarde dans l'aide, fouille tous les menus...
Si c'est bon, crée un fichier "Exporter calques en fichiers.js" (dans le dossier "Scrips" si il existe déjà) et colle dedans le code qui suit (celui de Photoshop 8)
// Copyright 2003. Adobe Systems, Incorporated. All rights reserved.
// This script will export each layer in the document to a separate file.
// debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
$.level = 0;
// debugger; // launch debugger on next line
//=================================================================
// Globals
//=================================================================
// UI strings to be localized
var uiTitleLayersToFiles = "Exporter calques en fichiers";
var uiButtonRun = "Exécuter";
var uiButtonCancel = "Annuler";
var uiHelpText = "Indiquez le format et l'emplacement d'enregistrement de chaque calque en tant que fichier.";
var uiLabelDestination = "Destination :";
var uiButtonBrowse = "Parcourir...";
var uiLabelFileNamePrefix = "Préfixe du nom de fichier :";
var uiCheckboxVisibleOnly = "Calques visibles seulement";
var uiLabelFileType = "Type de fichier :";
var uiCheckboxIncludeICCProfile = "Inclure le profil ICC";
var uiPanelJPEGOptions = "Options JPEG :";
var uiLabelQuality = "Qualité :";
var uiPanelPSDOptions = "Options PSD :";
var uiCheckboxMaximizeCompatibility = "Maximiser la compatibilité";
var uiPanelTIFFOptions = "Options TIFF :";
var uiLabelImageCompression = "Compression d'image :";
var uiRadiobuttonNone = "Sans";
var uiPanelPDFOptions = "Options PDF :";
var uiLabelEncoding = "Codage :";
var uiPanelTargaOptions = "Options Targa :";
var uiLabelDepth = "Profondeur :";
var uiRadiobutton16bit = "16 bits";
var uiRadiobutton24bit = "24 bits";
var uiRadiobutton32bit = "32 bits";
var uiPanelBMPOptions = "Options BMP :";
var uiAlertSpecifyDestination = "Indiquez la destination.";
var uiAlertDestinationNotExist = "La destination n'existe pas.";
var uiTitleSelectDestination = "Sélectionner la destination";
var uiAlertDocumentMustBeOpened = "Vous devez ouvrir un document pour exporter !";
var uiAlertNeedMultipleLayers = "Vous devez ouvrir un document comportant plusieurs calques pour exporter !";
var uiAlertWasSuccessful = " a abouti.";
var uiAlertFaild = " a échoué.";
//=================================================================
// Functions
//=================================================================
// main dialog
function settingDialog(exportInfo)
{
var dlgW = 390; // dialog width
var dlgH = 405; // dialog height
var btnW = 80; // botton width
var btnH = 20; // botton height
var txtW = 270; // text width
var txtH = 20; // text height
var mgn = 10; // margin
var pnlW = txtW;// panel width
var pnlH = 190; // panel height
var rb1W = 70; // radio botton width level1
var rb2W = 55; // radio botton width level2
var rbH = 20; // radio botton height
var labelW = 60; // JPEG quality label width
var editW = 25; // JPEG quality edit width
var bounds;
var yLayout = mgn+txtH; // scanning y layout
bounds = {x:0, y:0, width:dlgW, height:dlgH};
var w = new Window("dialog", uiTitleLayersToFiles, bounds );
bounds = {x:dlgW-btnW-mgn, y:yLayout, width:btnW, height:btnH};
w.btnRun = w.add("button", bounds, uiButtonRun, {name: "ok"});
w.btnRun.onClick = btnRunOnClick;
yLayout += btnH + mgn;
bounds = {x:dlgW-btnW-mgn, y:yLayout, width:btnW, height:btnH};
w.btnCancel = w.add("button", bounds, uiButtonCancel, {name: "cancel"});
w.btnCancel.onClick = function() { this.parent.close(0); };
yLayout = mgn; // reset
bounds = {x:mgn, y:yLayout, width:180, height:txtH}; // if the bounds is too wide, "browse" button does not work.
w.add("statictext", bounds, uiLabelDestination);
yLayout += txtH;
bounds = {x:mgn, y:yLayout, width:txtW-btnW-mgn-5, height:txtH}; // 5px smaller
w.etDestination = w.add("edittext", bounds, exportInfo.destination.toString());
bounds = {x:mgn+txtW-btnW-5, y:yLayout, width:btnW+5, height:btnH}; // 5px wider
w.btnBrowse= w.add("button", bounds, uiButtonBrowse);
w.btnBrowse.onClick = btnBrowseOnClick;
yLayout += txtH + mgn;
bounds = {x:mgn, y:yLayout, width:txtW, height:txtH};
w.add("statictext", bounds, uiLabelFileNamePrefix);
yLayout += txtH;
bounds = {x:mgn, y:yLayout, width:txtW, height:txtH};
w.etFileNamePrefix = w.add("edittext", bounds, exportInfo.fileNamePrefix.toString());
yLayout += txtH + mgn;
bounds = {x:mgn, y:yLayout, width:txtW, height:txtH};
w.cbVisible = w.add( "checkbox", bounds, uiCheckboxVisibleOnly);
w.cbVisible.value = exportInfo.visibleOnly;
yLayout += txtH + mgn;
bounds = {x:mgn, y:yLayout, width:pnlW, height:pnlH};
w.pnlFT = w.add( "panel", bounds, uiLabelFileType );
bounds = {x:mgn, y:mgn*2, width:rb1W, height:rbH};
w.pnlFT.rbJpg = w.pnlFT.add( "radiobutton", bounds, "JPEG" );
w.pnlFT.rbJpg.onClick = rbJpgOnClick;
bounds = {x:mgn*2+rb1W, y:mgn*2, width:rb1W, height:rbH};
w.pnlFT.rbPsd = w.pnlFT.add( "radiobutton", bounds, "PSD" );
w.pnlFT.rbPsd.onClick = rbPsdOnClick;
bounds = {x:mgn*3+rb1W*2, y:mgn*2, width:rb1W, height:rbH};
w.pnlFT.rbTif = w.pnlFT.add( "radiobutton", bounds, "TIFF" );
w.pnlFT.rbTif.onClick = rbTifOnClick;
bounds = {x:mgn, y:mgn*2+rbH, width:rb1W, height:rbH};
w.pnlFT.rbPdf = w.pnlFT.add( "radiobutton", bounds, "PDF" );
w.pnlFT.rbPdf.onClick = rbPdfOnClick;
bounds = {x:mgn*2+rb1W, y:mgn*2+rbH, width:rb1W, height:rbH};
w.pnlFT.rbTrg = w.pnlFT.add( "radiobutton", bounds, "Targa" );
w.pnlFT.rbTrg.onClick = rbTrgOnClick;
bounds = {x:mgn*3+rb1W*2, y:mgn*2+rbH, width:rb1W, height:rbH};
w.pnlFT.rbBmp = w.pnlFT.add( "radiobutton", bounds, "BMP" );
w.pnlFT.rbBmp.onClick = rbBmpOnClick;
bounds = {x:mgn, y:mgn*2+rbH*2, width:180, height:txtH};
w.pnlFT.cbIcc = w.pnlFT.add( "checkbox", bounds, uiCheckboxIncludeICCProfile);
w.pnlFT.cbIcc.value = exportInfo.icc;
var boundsPanelOptions = {x:mgn, y:mgn*2+rbH*2+txtH, width:pnlW-mgn*2, height:pnlH-(mgn*3+rbH*2+txtH)};
w.pnlFT.pnlJpg = w.pnlFT.add( "panel", boundsPanelOptions, uiPanelJPEGOptions );
bounds = {x:mgn, y:mgn*2+3, width:labelW, height:txtH};
w.pnlFT.pnlJpg.add("statictext", bounds, uiLabelQuality);
bounds = {x:mgn+labelW, y:mgn*2, width:editW, height:txtH};
w.pnlFT.pnlJpg.etQuality = w.pnlFT.pnlJpg.add("edittext", bounds, exportInfo.jpegQuality.toString());
w.pnlFT.pnlPsd = w.pnlFT.add( "panel", boundsPanelOptions, uiPanelPSDOptions );
bounds = {x:mgn, y:mgn*2, width:180, height:txtH};
w.pnlFT.pnlPsd.cbMax = w.pnlFT.pnlPsd.add( "checkbox", bounds, uiCheckboxMaximizeCompatibility);
w.pnlFT.pnlPsd.cbMax.value = exportInfo.psdMaxComp;
w.pnlFT.pnlTif = w.pnlFT.add( "panel", boundsPanelOptions, uiPanelTIFFOptions );
bounds = {x:mgn, y:mgn*2, width:180, height:txtH};
w.pnlFT.pnlTif.add("statictext", bounds, uiLabelImageCompression);
bounds = {x:mgn, y:mgn*2+txtH, width:rb2W, height:rbH};
w.pnlFT.pnlTif.rbNone = w.pnlFT.pnlTif.add( "radiobutton", bounds, uiRadiobuttonNone);
w.pnlFT.pnlTif.rbNone.onClick = rbDiableJpegQuality;
bounds = {x:mgn*2+rb2W, y:mgn*2+txtH, width:rb2W, height:rbH};
w.pnlFT.pnlTif.rbLzw = w.pnlFT.pnlTif.add( "radiobutton", bounds, "LZW" );
w.pnlFT.pnlTif.rbLzw.onClick = rbDiableJpegQuality;
bounds = {x:mgn*2+rb2W*2, y:mgn*2+txtH, width:rb2W, height:rbH};
w.pnlFT.pnlTif.rbZip = w.pnlFT.pnlTif.add( "radiobutton", bounds, "ZIP" );
w.pnlFT.pnlTif.rbZip.onClick = rbDiableJpegQuality;
bounds = {x:mgn*2+rb2W*3, y:mgn*2+txtH, width:rb2W, height:rbH};
w.pnlFT.pnlTif.rbJpeg = w.pnlFT.pnlTif.add( "radiobutton", bounds, "JPEG" );
w.pnlFT.pnlTif.rbJpeg.onClick = rbEnableJpegQuality;
bounds = {x:mgn, y:mgn*3+txtH*2, width:labelW, height:txtH};
w.pnlFT.pnlTif.stQuality = w.pnlFT.pnlTif.add("statictext", bounds, uiLabelQuality);
bounds = {x:mgn+labelW, y:mgn*3+txtH*2, width:editW, height:txtH};
w.pnlFT.pnlTif.etQuality = w.pnlFT.pnlTif.add("edittext", bounds, exportInfo.tiffJpegQuality.toString());
switch (exportInfo.tiffCompression) {
case TIFFEncoding.NONE: w.pnlFT.pnlTif.rbNone.value = true; break;
case TIFFEncoding.TIFFLZW: w.pnlFT.pnlTif.rbLzw.value = true; break;
case TIFFEncoding.TIFFZIP: w.pnlFT.pnlTif.rbZip.value = true; break;
case TIFFEncoding.JPEG: w.pnlFT.pnlTif.rbJpeg.value = true; break;
default: w.pnlFT.pnlTif.rbNone.value = true; break;
}
if (TIFFEncoding.JPEG != exportInfo.tiffCompression) { // if not JPEG
w.pnlFT.pnlTif.stQuality.enabled = false;
w.pnlFT.pnlTif.etQuality.enabled = false;
}
w.pnlFT.pnlPdf = w.pnlFT.add( "panel", boundsPanelOptions, uiPanelPDFOptions );
bounds = {x:mgn, y:mgn*2, width:100, height:txtH};
w.pnlFT.pnlPdf.add("statictext", bounds, uiLabelEncoding);
bounds = {x:mgn, y:mgn*2+txtH, width:rb2W, height:rbH};
w.pnlFT.pnlPdf.rbZip = w.pnlFT.pnlPdf.add( "radiobutton", bounds, "ZIP" );
w.pnlFT.pnlPdf.rbZip.onClick = rbDiableJpegQuality;
bounds = {x:mgn*2+rb2W, y:mgn*2+txtH, width:rb2W, height:rbH};
w.pnlFT.pnlPdf.rbJpeg = w.pnlFT.pnlPdf.add( "radiobutton", bounds, "JPEG" );
w.pnlFT.pnlPdf.rbJpeg.onClick = rbEnableJpegQuality;
bounds = {x:mgn, y:mgn*3+txtH+rbH, width:labelW, height:rbH};
w.pnlFT.pnlPdf.stQuality = w.pnlFT.pnlPdf.add("statictext", bounds, uiLabelQuality);
bounds = {x:mgn+labelW, y:mgn*3+txtH+rbH, width:editW, height:txtH};
w.pnlFT.pnlPdf.etQuality = w.pnlFT.pnlPdf.add("edittext", bounds, exportInfo.pdfJpegQuality.toString());//
switch (exportInfo.pdfEncoding) {
case PDFEncoding.PDFZIP: w.pnlFT.pnlPdf.rbZip.value = true; break;
case PDFEncoding.JPEG: w.pnlFT.pnlPdf.rbJpeg.value = true; break;
default: w.pnlFT.pnlPdf.rbJpeg.value = true; break;
}
if (PDFEncoding.JPEG != exportInfo.pdfEncoding) { // if not JPEG
w.pnlFT.pnlPdf.stQuality.enabled = false;
w.pnlFT.pnlPdf.etQuality.enabled = false;
}
w.pnlFT.pnlTrg = w.pnlFT.add( "panel", boundsPanelOptions, uiPanelTargaOptions );
bounds = {x:mgn, y:mgn*2, width:180, height:txtH};
w.pnlFT.pnlTrg.add("statictext", bounds, uiLabelDepth);
bounds = {x:mgn, y:mgn*2+txtH, width:rb2W+10, height:rbH};
w.pnlFT.pnlTrg.rb16bit = w.pnlFT.pnlTrg.add( "radiobutton", bounds, uiRadiobutton16bit);
bounds = {x:mgn*2+rb2W, y:mgn*2+txtH, width:rb2W+10, height:rbH};
w.pnlFT.pnlTrg.rb24bit = w.pnlFT.pnlTrg.add( "radiobutton", bounds, uiRadiobutton24bit);
bounds = {x:mgn*3+rb2W*2, y:mgn*2+txtH, width:rb2W+10, height:rbH};
w.pnlFT.pnlTrg.rb32bit = w.pnlFT.pnlTrg.add( "radiobutton", bounds, uiRadiobutton32bit);
switch (exportInfo.targaDepth) {
case TargaBitsPerPixels.SIXTEEN: w.pnlFT.pnlTrg.rb16bit.value = true; break;
case TargaBitsPerPixels.TWENTYFOUR: w.pnlFT.pnlTrg.rb24bit.value = true; break;
case TargaBitsPerPixels.THIRTYTWO: w.pnlFT.pnlTrg.rb32bit.value = true; break;
default: w.pnlFT.pnlTrg.rb24bit.value = true; break;
}
w.pnlFT.pnlBmp = w.pnlFT.add( "panel", boundsPanelOptions, uiPanelBMPOptions );
bounds = {x:mgn, y:mgn*2, width:180, height:txtH};
w.pnlFT.pnlBmp.add("statictext", bounds, uiLabelDepth);
bounds = {x:mgn, y:mgn*2+txtH, width:rb2W+10, height:rbH};
w.pnlFT.pnlBmp.rb16bit = w.pnlFT.pnlBmp.add( "radiobutton", bounds, uiRadiobutton16bit);
bounds = {x:mgn*2+rb2W, y:mgn*2+txtH, width:rb2W+10, height:rbH};
w.pnlFT.pnlBmp.rb24bit = w.pnlFT.pnlBmp.add( "radiobutton", bounds, uiRadiobutton24bit);
bounds = {x:mgn*3+rb2W*2, y:mgn*2+txtH, width:rb2W+10, height:rbH};
w.pnlFT.pnlBmp.rb32bit = w.pnlFT.pnlBmp.add( "radiobutton", bounds, uiRadiobutton32bit);
switch (exportInfo.bmpDepth) {
case BMPDepthType.SIXTEEN: w.pnlFT.pnlBmp.rb16bit.value = true; break;
case BMPDepthType.TWENTYFOUR:w.pnlFT.pnlBmp.rb24bit.value = true; break;
case BMPDepthType.THIRTYTWO: w.pnlFT.pnlBmp.rb32bit.value = true; break;
default: w.pnlFT.pnlBmp.rb24bit.value = true; break;
}
bounds = {left:mgn, top:dlgH-mgn-50, right:dlgW-mgn, bottom:dlgH-mgn};
w.pnlHelp = w.add( "panel", bounds, "" );
bounds = {x:mgn, y:mgn, width:dlgW-mgn*4, height:30};
w.pnlHelp.add("statictext", bounds, uiHelpText, {multiline:true});
hideAllFileTypePanel(w.pnlFT);
switch (exportInfo.fileType) { // default setting
case 1: w.pnlFT.rbJpg.value = true; w.pnlFT.pnlJpg.visible = true; break;
case 2: w.pnlFT.rbPsd.value = true; w.pnlFT.pnlPsd.visible = true; break;
case 3: w.pnlFT.rbTif.value = true; w.pnlFT.pnlTif.visible = true; break;
case 4: w.pnlFT.rbPdf.value = true; w.pnlFT.pnlPdf.visible = true; break;
case 5: w.pnlFT.rbTrg.value = true; w.pnlFT.pnlTrg.visible = true; break;
case 6: w.pnlFT.rbBmp.value = true; w.pnlFT.pnlBmp.visible = true; break;
default: w.pnlFT.rbPsd.value = true; w.pnlFT.pnlPsd.visible = true; break;
}
w.center(); // centering dialog
var result = w.show();
if ( 0 == result) return result; // close to quit
// get setting from dialog
exportInfo.destination = w.etDestination.text;
exportInfo.fileNamePrefix = w.etFileNamePrefix.text;
exportInfo.visibleOnly = w.cbVisible.value;
if (w.pnlFT.rbJpg.value) exportInfo.fileType = 1;
if (w.pnlFT.rbPsd.value) exportInfo.fileType = 2;
if (w.pnlFT.rbTif.value) exportInfo.fileType = 3;
if (w.pnlFT.rbPdf.value) exportInfo.fileType = 4;
if (w.pnlFT.rbTrg.value) exportInfo.fileType = 5;
if (w.pnlFT.rbBmp.value) exportInfo.fileType = 6;
exportInfo.icc = w.pnlFT.cbIcc.value;
exportInfo.jpegQuality = w.pnlFT.pnlJpg.etQuality.text;
exportInfo.psdMaxComp = w.pnlFT.pnlPsd.cbMax.value;
if (w.pnlFT.pnlTif.rbNone.value) exportInfo.tiffCompression = TIFFEncoding.NONE;
if (w.pnlFT.pnlTif.rbLzw.value) exportInfo.tiffCompression = TIFFEncoding.TIFFLZW;
if (w.pnlFT.pnlTif.rbZip.value) exportInfo.tiffCompression = TIFFEncoding.TIFFZIP;
if (w.pnlFT.pnlTif.rbJpeg.value) exportInfo.tiffCompression = TIFFEncoding.JPEG;
exportInfo.tiffJpegQuality = w.pnlFT.pnlTif.etQuality.text;
if (w.pnlFT.pnlPdf.rbZip.value) exportInfo.pdfEncoding = PDFEncoding.PDFZIP;
if (w.pnlFT.pnlPdf.rbJpeg.value) exportInfo.pdfEncoding = PDFEncoding.JPEG;
exportInfo.pdfJpegQuality = w.pnlFT.pnlPdf.etQuality.text;
if (w.pnlFT.pnlTrg.rb16bit.value) exportInfo.targaDepth = TargaBitsPerPixels.SIXTEEN;
if (w.pnlFT.pnlTrg.rb24bit.value) exportInfo.targaDepth = TargaBitsPerPixels.TWENTYFOUR;
if (w.pnlFT.pnlTrg.rb32bit.value) exportInfo.targaDepth = TargaBitsPerPixels.THIRTYTWO;
if (w.pnlFT.pnlBmp.rb16bit.value) exportInfo.bmpDepth = BMPDepthType.SIXTEEN;
if (w.pnlFT.pnlBmp.rb24bit.value) exportInfo.bmpDepth = BMPDepthType.TWENTYFOUR;
if (w.pnlFT.pnlBmp.rb32bit.value) exportInfo.bmpDepth = BMPDepthType.THIRTYTWO;
return result;
}
function hideAllFileTypePanel(panel) // call back function
{
panel.pnlJpg.visible = false;
panel.pnlPsd.visible = false;
panel.pnlTif.visible = false;
panel.pnlPdf.visible = false;
panel.pnlTrg.visible = false;
panel.pnlBmp.visible = false;
}
function rbJpgOnClick(exportInfo) // call back function
{
hideAllFileTypePanel(this.parent);
this.parent.pnlJpg.visible = true;
this.parent.cbIcc.enabled = true;
}
function rbPsdOnClick() // call back function
{
hideAllFileTypePanel(this.parent);
this.parent.pnlPsd.visible = true;
this.parent.cbIcc.enabled = true;
}
function rbTifOnClick() // call back function
{
hideAllFileTypePanel(this.parent);
this.parent.pnlTif.visible = true;
this.parent.cbIcc.enabled = true;
}
function rbPdfOnClick() // call back function
{
hideAllFileTypePanel(this.parent);
this.parent.pnlPdf.visible = true;
this.parent.cbIcc.enabled = true;
}
function rbTrgOnClick() // call back function
{
hideAllFileTypePanel(this.parent);
this.parent.pnlTrg.visible = true;
this.parent.cbIcc.enabled = false;
}
function rbBmpOnClick() // call back function
{
hideAllFileTypePanel(this.parent);
this.parent.pnlBmp.visible = true;
this.parent.cbIcc.enabled = false;
}
function rbDiableJpegQuality() // call back function
{
this.parent.etQuality.enabled = false;
this.parent.stQuality.enabled = false;
}
function rbEnableJpegQuality() // call back function
{
this.parent.etQuality.enabled = true;
this.parent.stQuality.enabled = true;
}
function btnRunOnClick() // call back function
{
// check if the setting is properly
var destination = this.parent.etDestination.text;
if (destination.length == 0) {
alert(uiAlertSpecifyDestination);
return;
}
var testFolder = new Folder(destination);
if (!testFolder.exists) {
alert(uiAlertDestinationNotExist);
return;
}
this.parent.close(1);
}
function btnBrowseOnClick() // call back function
{
var defaultFolder = this.parent.etDestination.text;
var testFolder = new Folder(this.parent.etDestination.text);
if (!testFolder.exists) defaultFolder = "~";
var selFolder = Folder.selectDialog(uiTitleSelectDestination, defaultFolder);
if ( selFolder != null ) {
this.parent.etDestination.text = selFolder.fsName;
}
return;
}
// It carries dialog setting.
function initExportInfo(exportInfo)
{
exportInfo.destination = new String("" );
exportInfo.fileNamePrefix = new String("untitled_" );
exportInfo.visibleOnly = false;
exportInfo.fileType = 2; // JPEG=1, PSD=2, TIFF=3, PDF=4, Targa=5, BMP=6
exportInfo.icc = true;
exportInfo.jpegQuality = 8;
exportInfo.psdMaxComp = true;
exportInfo.tiffCompression = TIFFEncoding.NONE;
exportInfo.tiffJpegQuality = 8;
exportInfo.pdfEncoding = PDFEncoding.JPEG;
exportInfo.pdfJpegQuality = 8;
exportInfo.targaDepth = TargaBitsPerPixels.TWENTYFOUR;
exportInfo.bmpDepth = BMPDepthType.TWENTYFOUR;
try {
exportInfo.destination = Folder(app.activeDocument.fullName.parent).fsName; // destination folder
var tmp = app.activeDocument.fullName.name;
exportInfo.fileNamePrefix = decodeURI(tmp.substring(0, tmp.indexOf("." ))); // filename body part
} catch(someError) {
exportInfo.destination = new String("" );
exportInfo.fileNamePrefix = app.activeDocument.name; // filename body part
}
}
function saveFile( docRef, fileNameBody, exportInfo)
{
switch (exportInfo.fileType) {
case 1: // JPEG
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".jpg" );
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = exportInfo.icc;
jpgSaveOptions.quality = exportInfo.jpegQuality;
docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
break;
case 2: // PSD
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".psd" );
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = exportInfo.icc;
psdSaveOptions.maximizeCompatibility = exportInfo.psdMaxComp;
docRef.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
break;
case 3: // TIFF
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".tif" );
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = exportInfo.icc;
tiffSaveOptions.imageCompression = exportInfo.tiffCompression;
if (TIFFEncoding.JPEG == exportInfo.tiffCompression) tiffSaveOptions.jpegQuality = exportInfo.tiffJpegQuality;
docRef.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
break;
case 4: // PDF
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".pdf" );
pdfSaveOptions = new PDFSaveOptions();
pdfSaveOptions.embedColorProfile = exportInfo.icc;
pdfSaveOptions.encoding = exportInfo.pdfEncoding;
if (PDFEncoding.JPEG == exportInfo.pdfEncoding) pdfSaveOptions.jpegQuality = exportInfo.pdfJpegQuality;
docRef.saveAs(saveFile, pdfSaveOptions, true, Extension.LOWERCASE);
break;
case 5: // Targa
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".tga" );
targaSaveOptions = new TargaSaveOptions();
targaSaveOptions.resolution = exportInfo.targaDepth;
docRef.saveAs(saveFile, targaSaveOptions, true, Extension.LOWERCASE);
break;
case 6: // BMP
var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".bmp" );
bmpSaveOptions = new BMPSaveOptions();
bmpSaveOptions.depth = exportInfo.bmpDepth;
docRef.saveAs(saveFile, bmpSaveOptions, true, Extension.LOWERCASE);
break;
default:
alert("Unexpected error" );
break;
}
}
function zeroSuppress (num, digit)
{
var tmp = num.toString();
while(tmp.length < digit) tmp = "0" + tmp;
return tmp
}
function setInvisibleAllArtLayers(obj) // obj can be DocRef or LayerSet
{
for( var i = 0; i < obj.artLayers.length; i++) {
obj.artLayers[i].allLocked = false; // unlock first
obj.artLayers[i].visible = false;
}
for( var i = 0; i < obj.layerSets.length; i++) {
setInvisibleAllArtLayers(obj.layerSets[i]); // recursive call
}
}
function removeAllInvisibleArtLayers(obj) // obj can be DocRef or LayerSet
{
for( var i = obj.artLayers.length-1; 0 <= i; i--) {
try { // best effort
if(!obj.artLayers[i].visible) obj.artLayers[i].remove();
} catch (e) {}
}
for( var i = obj.layerSets.length-1; 0 <= i; i--) {
removeAllInvisibleArtLayers(obj.layerSets[i]); // recursive call
}
}
function removeAllEmptyLayerSets(obj) // obj can be DocRef or LayerSet
{
var foundEmpty = true;
for( var i = obj.layerSets.length-1; 0 <= i; i--) {
if( removeAllEmptyLayerSets(obj.layerSets[i])) { // if empty
obj.layerSets[i].remove();
} else {
foundEmpty = false; // it is not empty
}
}
if (obj.artLayers.length > 0) foundEmpty = false;
return foundEmpty; // return boolean / if empty
}
function removeAllInvisible(docRef)
{
removeAllInvisibleArtLayers(docRef);
removeAllEmptyLayerSets(docRef);
}
function exportChildren(dupObj, orgObj, exportInfo, dupDocRef, fileNamePrefix) // obj can be DocRef or LayerSet
{
for( var i = 0; i < dupObj.artLayers.length; i++) {
if (exportInfo.visibleOnly) { // visible layer only
if (!orgObj.artLayers[i].visible) continue;
}
dupObj.artLayers[i].visible = true;
var layerName = dupObj.artLayers[i].name; // store layer name before change doc
var duppedDocumentTmp = dupDocRef.duplicate();
if (2 == 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);
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
if (!orgObj.layerSets[i].visible) continue;
}
var fileNameBody = fileNamePrefix;
fileNameBody += "_" + zeroSuppress(i, 4) + "s";
exportChildren(dupObj.layerSets[i], orgObj.layerSets[i], exportInfo, dupDocRef, fileNameBody); // recursive call
}
}
function main()
{
if ( app.documents.length <= 0 ) {
alert( uiAlertDocumentMustBeOpened );
return;
}
var exportInfo = new Object();
initExportInfo(exportInfo);
if (0 == settingDialog(exportInfo)) return; // quit
try {
var docName = app.activeDocument.name; // save the app.activeDocument name before duplicate.
var layerCount = app.documents[docName].layers.length;
var layerSetsCount = app.documents[docName].layerSets.length;
if ((layerCount <= 1)&&(layerSetsCount <= 0)) {
alert ( uiAlertNeedMultipleLayers );
} else {
app.activeDocument = app.documents[docName];
var duppedDocument = app.activeDocument.duplicate();
duppedDocument.activeLayer = duppedDocument.layers[duppedDocument.layers.length-1]; // for removing
setInvisibleAllArtLayers(duppedDocument);
exportChildren(duppedDocument, app.documents[docName], exportInfo, duppedDocument, exportInfo.fileNamePrefix);
duppedDocument.close( SaveOptions.DONOTSAVECHANGES );
alert(uiTitleLayersToFiles + uiAlertWasSuccessful);
}
} catch (e) {
alert(e);
}
}
//===============================================================
// Dispatch
//===============================================================
main();