10 Replies Latest reply on Nov 16, 2017 2:33 PM by whitefx

    Layer Comps to JPG Save for Web

    JeroenZicht

      Hello everyone,

       

      I'm using the "Layer comp to files" script a lot to send some designs to clients. And sometimes I need to send a lot of JPGs at once, wich are created with "Layer comps to files", but they are all around 300k or more, and when I use Safe for web it reduces the file size a lot! But I don't want todo it all manually again offcourse.

       

      So I was wondering, is there any script what saves your Layer Comps JPGs to a JPG what is compressed with the Save for Web technology?

       

      Thanks in advance.

       

       

      Jeroen

        • 1. Re: Layer Comps to JPG Save for Web
          Michael L Hale Level 5

          Find these lines in the script

           

          case jpegIndex:
               docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
               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;
          

           

          Replace with this

           

          case jpegIndex:
               docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
               var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".jpg");
               var exportOpts = new ExportOptionsSaveForWeb( ); 
               exportOpts.format = SaveDocumentType.JPEG
               exportOpts.includeProfile = exportInfo.icc;
               exportOpts.quality = Math.round( exportInfo.jpegQuality / 12 * 100 ) ); // exportInfo.jpegQuality is 0 to 12, SFW uses 0 to 100. this converts
               if ( saveFile.exists ) saveFile.remove( );// avoid file exists overwrite dialog
               docRef.exportDocument( saveFile, ExportType.SAVEFORWEB, exportOpts );
               break;
          

           

          And that should do it. Or you could adjust so it uses scriptlistner for the SFW like the script does for PNG. If you want the jpeg to keep some metadata you will need to use scriptlistner anyway as the DOM version doesn't allow metadata in export.

          • 2. Re: Layer Comps to JPG Save for Web
            JeroenZicht Level 1

            Hi Michael,

             

            Thanks for taking the time to answer my question. Really appreciated and I think we're almost getting there, but I'll get an error when I replace the lines with your script.

             

            The error:

             

            Error 23: does not have a value.
            Line: 697
            -> exportOpts.quality = Math.round( exportInfo.jpegQuality / 12 * 100 ) ); // exportInfo.jpegQuality is 0 to 12, SFW uses 0 to 100. this converts

             


            I hope this helps and you can help me further.

             

            Thanks in advance.

             

             

            Greetings Jeroen

            • 3. Re: Layer Comps to JPG Save for Web
              Michael L Hale Level 5

              Sorry, typo in the code. Remove the extra ) in that line.

              • 4. Re: Layer Comps to JPG Save for Web
                JeroenZicht Level 1

                Perfect! Thanks a lot for helping.

                 

                For the people who think this is helpfull too, I'll paste the script here, without the typo

                 

                 

                case jpegIndex:
                     docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
                     var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".jpg");
                     var exportOpts = new ExportOptionsSaveForWeb( );
                     exportOpts.format = SaveDocumentType.JPEG
                     exportOpts.includeProfile = exportInfo.icc;
                     exportOpts.quality = Math.round( exportInfo.jpegQuality / 12 * 100 ); // exportInfo.jpegQuality is 0 to 12, SFW uses 0 to 100. this converts
                     if ( saveFile.exists ) saveFile.remove( );// avoid file exists overwrite dialog
                     docRef.exportDocument( saveFile, ExportType.SAVEFORWEB, exportOpts );
                     break;

                • 5. Re: Layer Comps to JPG Save for Web
                  Twisted Rooster

                  Hi JeroenZicht,

                   

                  Is this the full script? I've tried taking your script dumping it into a text file and saving it "SaveForWeb.js" with only your source and it fails on CS4 Photoshop.

                   

                  I'm sure I'm doing something wrong but is this the full script?

                   

                  Thanks,

                  S.

                  • 8. Re: Layer Comps to JPG Save for Web
                    Michael L Hale Level 5

                    I think Paul posted a link to the wrong script by mistake. The two are very similar.

                     

                    Here is the link to the Layers Comps to Files script modified to use sfw. http://ps-scripts.com/bb/viewtopic.php?f=10&t=3657

                    • 9. Re: Layer Comps to JPG Save for Web
                      IlMostro

                      Thanks guys, worked awesomely.

                      • 10. Re: Layer Comps to JPG Save for Web
                        whitefx Level 1

                        I have tried modifying this script for PS CC 2015.5 and do not see any differences in the functionality of the stock script. I noticed that the 2015.5 version of the script includes "fileExtension = "jpg";" as shown below:

                         

                                  case jpegIndex:
                                   fileExtension = "jpg";
                                     docRef.bitsPerChannel = BitsPerChannelType.EIGHT;
                                     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;