• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help with javascript - Photoshop Save LayerComps for web in specific user defined folder

New Here ,
Jan 25, 2016 Jan 25, 2016

Copy link to clipboard

Copied

Hi everyone! Here's my issue:

I am working with photoshop files that are designs for animated web banners. All of the different frames are listed as Layer Comps (eg. Frame 1, Frame 2, bkg, overlay, etc). We have been manually selecting the layer comp and then Save for Web and selecting our options. The bkg is being saved for web as a jpg, and the other frames are being saved for web as png(s).

I would love some assistance creating a script that would prompt the user for an output folder, and then automatically select the layer comp, and save it out with the appropriate settings.

JPEG

Compression High, Quality 80%. No other options selected.

PNG-24

Transparency Yes, No other options selected.

I have found scripts for Save for Web - Jpeg and PNG. My main issue is combining them, selecting the correct profile dependent on the name of the layer comp, and defining an output folder.

Any help or resources that you could send me to look into would be much appreciated.

TOPICS
Actions and scripting

Views

324

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
New Here ,
Jan 25, 2016 Jan 25, 2016

Copy link to clipboard

Copied

Here are the two scripts that I have found to help me on my way.

Save for Web - jpg

function main(){ 

if(!documents.length) return; 

var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');  

var saveFile = File(Folder.desktop + "/" + Name + ".jpg"); 

if(saveFile.exists){ 

   if(!confirm("Overwrite existing document?")) return; 

    saveFile.remove(); 

    } 

SaveForWeb(saveFile,100); //change to 60 for 60% 

main(); 

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

Save for Web - png

function main() {

          // declare local variables

          var doc = app.activeDocument;

          var docName = app.activeDocument.name.slice(0,-4);

     var saveFile = new File("~/Desktop/" + docName + ".png");

    pngSaveOptions = new PNGSaveOptions();

    pngSaveOptions.interlaced = false;

    doc.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);

}

main();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 26, 2016 Jan 26, 2016

Copy link to clipboard

Copied

LATEST

Hi Elven,

Try this Code..

Like this order Layer comp..(Frame 1...n,bg,overlay)

Screen Shot 2016-01-26 at 4.26.14 pm.png

-yajiv

#target photoshop 

app.bringToFront(); 

var outputfolder;

main();

function main(){

    if(!documents.length) return;     

    outputfolder=Folder("~/Desktop/Results/");

    if(!outputfolder.exists){outputfolder.create();}    

    var docRef = app.activeDocument; 

    var docName=docRef.name.replace(/\.[^\.]+$/, '');  

    var docPath = app.activeDocument.path; 

    var n= docRef.layerComps.length ;   

for(i=0;i<n;i++){ 

    var layCom=docRef.layerComps.name;

    var FileName=docName+"_"+docRef.layerComps.name;

   

    if(layCom=="Frame "+ (i+1) || layCom=="overlay"){

        docRef.layerComps.apply(); 

        OutFoldPNG(docRef,FileName);

        }

    else if(layCom=="bg"){

        docRef.layerComps.apply(); 

        OutFoldJPG(FileName);

        }

    } 

}

function OutFoldJPG(docName){   

    var saveFile = File(outputfolder+ "/"+docName + ".jpg");   

    if(saveFile.exists){   

       if(!confirm("Overwrite existing document?")) return;   

            saveFile.remove();   

        }   

    SaveForWeb(saveFile,100); //change to 60 for 60%   

}   

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

}   

function OutFoldPNG(doc,docName) {

    var saveFile = new File(outputfolder + "/"+ docName + ".png"); 

    pngSaveOptions = new PNGSaveOptions(); 

    pngSaveOptions.interlaced = false; 

    doc.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE); 

}  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines