2 Replies Latest reply on Mar 1, 2012 5:11 AM by Juano Hunt

    A script for "Save for Web" as .jpg

    Juano Hunt

      I found a script that saves the current selected document in Photoshop as .png to the Desktop, and use it all the time.

       

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

       

       

      Now I'd really like a similar script to do "Save for Web" as .jpg files, without a colour profile, to the Desktop. Preferably a version to save as 100% quality and one to save as 60% quality.

      Any help would be greatly appreciated.

        • 1. Re: A script for "Save for Web" as .jpg
          Paul Riggott Level 6

          Here you are...

           

           

          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);
          }
          
          
          • 2. Re: A script for "Save for Web" as .jpg
            Juano Hunt Level 1

            Perfect! Thanks a lot