8 Replies Latest reply on Dec 5, 2017 1:03 PM by Cyril500

    For animated gifs: gifsicle sets Photoshops SaveForWeb parameter "lossy" to 60 that cannot be changed.

    Cyril500 Level 1

      To batch save animated gifs I am using the great script written by SuperMerlin . Here it is:

       

      #target photoshop; 

      try{ 

      var Path= activeDocument.path; 

      }catch(e){var Path = "~/desktop";} 

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

      var layerName = app.activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_"); 

      var saveFile= new File(Path + "/" + Name + "-" + layerName + ".gif"); 

      var rex = new RegExp(Name + "-" + layerName + ".gif"); 

      var files = decodeURI(saveFile.fsName).replace(rex,"*.gif"); 

      var cmd = 'C:/gifsicle.exe --batch --loop=forever --careful '; 

      cmd += '\"' + files+ '\"'; 

      SaveForWeb(saveFile); 

      app.system(cmd); 

      function SaveForWeb(saveFile) { 

      var sfwOptions = new ExportOptionsSaveForWeb(); 

         sfwOptions.format = SaveDocumentType.COMPUSERVEGIF; 

         sfwOptions.includeProfile = false; 

         sfwOptions.interlaced = 0; 

         sfwOptions.optimized = true; 

         sfwOptions.transparency = 1; 

         sfwOptions.ColorReductionType = ColorReductionType.SELECTIVE; 

         sfwOptions.dither = Dither.NONE;   

         sfwOptions.ditherAmount = 0; 

         sfwOptions.lossy = 8;  

         sfwOptions.webSnap = 0; 

         sfwOptions.colors = 256; 

      activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions); 

      };

       

      And everything was great until I reinstall my computer. It looks like all photoshop and system parameters are as they were before but all my animated Gifs start to apear in a very poor quality after gifsicle. Exactly as poor as if you set in Export Option - SaveForWeb - parameter "lossy" to 60 for your animted gif.

       

      If you open SaveForWeb - lossy is always set to 60 by default after using gifsicle. Otherwise it sets by default to whatever value was previously used.

       

      I cannot fight that. Nothing helps so far. Would be very grateful for any help!

        • 2. Re: For animated gifs: gifsicle sets Photoshops SaveForWeb parameter "lossy" to 60 that cannot be changed.
          r-bin Level 5

          Are you sure that this function worked for you? I doubt her adequacy at all. It in my opinion uses unknown parameters and you just got lucky.

           

          Try to exit Photoshop and delete the files

           

          C: \ Users \ <USERNAME> \ AppData \ Local \ Adobe Save for Web 13.0 Prefs

           

          And also specifically for your version of the photoshop, for example

          for CS6

          C: \ Users \ <USERNAME> \ AppData \ Roaming \ Adobe \ Adobe Photoshop CS6 \ Adobe Photoshop CS6 \ Recently Used Optimizations.irs

           

          for CC2018

          C: \ Users \ <USERNAME> \ AppData \ Roaming \ Adobe \ Adobe Photoshop CC 2018 \ Adobe Photoshop CC 2018 \ Recently Used Optimizations.irs

           

          Start Photoshop, manually call Save For Web and press "Done".

           

          Check how your script works.

           

           

          In general, try to use another version of the Save For Web call

          The full script

           

          #target photoshop; 
          try{ 
          var Path= activeDocument.path; 
          }catch(e){var Path = "~/desktop";} 
          var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, ''); 
          var layerName = app.activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_"); 
          var saveFile= new File(Path + "/" + Name + "-" + layerName + ".gif"); 
          var rex = new RegExp(Name + "-" + layerName + ".gif"); 
          var files = decodeURI(saveFile.fsName).replace(rex,"*.gif"); 
          var cmd = 'C:/gifsicle.exe --batch --loop=forever --careful '; 
          cmd += '\"' + files+ '\"'; 
          SaveForWeb(saveFile); 
          app.system(cmd); 
          
          
          //////////////////////////////////////////////////
          function SaveForWeb(file)
              {
              try
                  {
                  var d = new ActionDescriptor()
          
                  d.putEnumerated( charIDToTypeID( "Op  " ), charIDToTypeID( "SWOp" ), charIDToTypeID( "OpSa" ) ); // Save
          
                  d.putPath( charIDToTypeID( "In  " ), file );
          
                  d.putEnumerated( charIDToTypeID( "Fmt " ), charIDToTypeID( "IRFm" ), charIDToTypeID( "GIFf" ) ); // GIF format
                  
                  d.putBoolean( charIDToTypeID( "Intr" ), false ); // Interlaced
                  
                  d.putEnumerated( charIDToTypeID( "RedA" ), charIDToTypeID( "IRRd" ), charIDToTypeID( "Sltv" ) ); // Colors Rreduction Type
              
                  d.putBoolean( charIDToTypeID( "RChT" ), false ); // colors reduction Use All Text Layers
                  d.putBoolean( charIDToTypeID( "RChV" ), false ); // colors reduction Use All Vector Shape Layers
                  d.putBoolean( charIDToTypeID( "AuRd" ), false ); // colors reduction Auto
                  d.putInteger( charIDToTypeID( "NCol" ), 256 );
                  
                  d.putEnumerated( charIDToTypeID( "Dthr" ), charIDToTypeID( "IRDt" ), charIDToTypeID( "None" ) ); // Dither type
                  d.putInteger( charIDToTypeID( "DthA" ), 0 ); // Dither amount
              
                  d.putInteger( charIDToTypeID( "DChS" ), 0 );     // Diffusion Dither min if Use
                  d.putInteger( charIDToTypeID( "DCUI" ), 0 );     // Diffusion Dither max if Use
                  d.putBoolean( charIDToTypeID( "DChT" ), false ); // Diffusion Dither Use All Text Layers        
                  d.putBoolean( charIDToTypeID( "DChV" ), false ); // Diffusion Dither Use All Vector Shape Layers
              
                  d.putInteger( charIDToTypeID( "WebS" ), 0 ); // Web Snap
                  
                  d.putEnumerated( charIDToTypeID( "TDth" ), charIDToTypeID( "IRDt" ), charIDToTypeID( "None" ) ); // Trancparency dither type
                  d.putInteger( charIDToTypeID( "TDtA" ), 0 ); // Trancparency diffusion dither amount;
                  
                  d.putInteger( charIDToTypeID( "Loss" ), 8 ); // Lossy amount
                  
                  d.putInteger( charIDToTypeID( "LChS" ), 0   );   // lossiness min
                  d.putInteger( charIDToTypeID( "LCUI" ), 100 );   // lossiness max
                  d.putBoolean( charIDToTypeID( "LChT" ), false ); // lossiness Use All Text Layers        
                  d.putBoolean( charIDToTypeID( "LChV" ), false ); // lossiness Use All Vector Shape Layers
                  
                  d.putBoolean( charIDToTypeID( "Trns" ), true );  // Trancparency
                  
                  d.putBoolean( charIDToTypeID( "Mtt " ), false ); // Matte
                  d.putInteger( charIDToTypeID( "MttR" ), 255 );   // Matte R
                  d.putInteger( charIDToTypeID( "MttG" ), 255 );   // Matte G
                  d.putInteger( charIDToTypeID( "MttB" ), 255 );   // Matte B
                  
                  var d0 = new ActionDescriptor();
                  d0.putObject( charIDToTypeID( "Usng" ), stringIDToTypeID( "SaveForWeb" ), d );
          
                  executeAction( charIDToTypeID( "Expr" ), d0, DialogModes.NO );
                  }
              catch (e) { alert(e); }
              }
          
          
          
          
          1 person found this helpful
          • 3. Re: For animated gifs: gifsicle sets Photoshops SaveForWeb parameter "lossy" to 60 that cannot be changed.
            Cyril500 Level 1

            Thank you very much for your answers!

             

            Yes, it worked but it didn't  start working again so far...

             

            But your script works great!!!

            • 4. Re: For animated gifs: gifsicle sets Photoshops SaveForWeb parameter "lossy" to 60 that cannot be changed.
              Cyril500 Level 1

              2017-12-05_21-09-53.png

               

              Could you please tell me what I do wrong?

               

              I try to change Dither from NONE to PATTERN

               

              And I changed it as on the image - but it says "Error: Illegal Argument". Could you please tell how can change it?

              • 5. Re: For animated gifs: gifsicle sets Photoshops SaveForWeb parameter "lossy" to 60 that cannot be changed.
                r-bin Level 5
                d.putEnumerated( charIDToTypeID( "Dthr" ), charIDToTypeID( "IRDt" ), charIDToTypeID( "Ptrn" ) );
                

                 

                or

                 

                d.putEnumerated( charIDToTypeID( "Dthr" ), charIDToTypeID( "IRDt" ), stringIDToTypeID( "pattern" ) );
                
                • 6. Re: For animated gifs: gifsicle sets Photoshops SaveForWeb parameter "lossy" to 60 that cannot be changed.
                  Cyril500 Level 1

                  Great!!! It works!!! Thank you so much!!!

                   

                  Could you please tell - is it a listener? If yes, could you please tell - what kind of listener? Where I can get it?

                  • 7. Re: For animated gifs: gifsicle sets Photoshops SaveForWeb parameter "lossy" to 60 that cannot be changed.
                    r-bin Level 5

                    Yes I used the ScriptListener

                     

                    You can download the ScriptingListener plug-in here.Downloadable plug-ins and content in Photoshop


                    After using it, you need to delete it so that the log does not grow).