8 Replies Latest reply on Feb 4, 2011 1:47 PM by Paul Riggott

    multiple images batch resize and rename

    strife_quio

      ok so im new to javascript and just know how to navigate through it. My task is to upload many pics to the web in diferent squared dimentions(50,80,100,150,250,400,600) So what i need to do is take the master (which I squared already) and output all those file sizes and with corisponding file extention name ( 150px pic has file name "originalname_150.png) I can do this in batch with actions but have to do this with each file size. I need it to do it to all files in folder then make sub folder with all sizes listed.

       

      I took this and edited it, probally off

       

      // size
      var fWidth = 600;
      var fHeight = 600;

       

      // our web export options
      var options = new ExportOptionsSaveForWeb(); <------ says it dosnt have constructor in extendscript toolkit
      options.quality = 70;
      options.format = SaveDocumentType.PNG;

       

      var newName = doc.name+ '_400' + '.png';

       

      doc.exportDocument(File(doc.path+'/'+newName));

       

      can i just make a one for one size that resizes and names and saves, then copy paste it below with new size, would that work?

       

      anything will help guys

        • 1. Re: multiple images batch resize and rename
          Paul Riggott Level 6

          If the document is square this should be close...

           

          #target photoshop
          main();
          function main(){
          if(!documents.length) return;
          var startRulerUnits = app.preferences.rulerUnits;
          app.preferences.rulerUnits = Units.PIXELS;
          var doc = app.activeDocument;
          var Name = doc.name.replace(/\.[^\.]+$/, '');
          var Path = decodeURI(doc.path);
          doc.resizeImage(600, undefined, undefined, ResampleMethod.BICUBICSHARPER);
          var saveFile = File(Path +"/"+Name+"_600.png");
          sfwPNG24(saveFile);
          doc.resizeImage(400, undefined, undefined, ResampleMethod.BICUBICSHARPER);
          var saveFile = File(Path +"/"+Name+"_400.png");
          sfwPNG24(saveFile);
          doc.resizeImage(250, undefined, undefined, ResampleMethod.BICUBICSHARPER);
          var saveFile = File(Path +"/"+Name+"_250.png");
          sfwPNG24(saveFile);
          doc.resizeImage(150, undefined, undefined, ResampleMethod.BICUBICSHARPER);
          var saveFile = File(Path +"/"+Name+"_150.png");
          sfwPNG24(saveFile);
          doc.resizeImage(100, undefined, undefined, ResampleMethod.BICUBICSHARPER);
          var saveFile = File(Path +"/"+Name+"_100.png");
          sfwPNG24(saveFile);
          doc.resizeImage(80, undefined, undefined, ResampleMethod.BICUBICSHARPER);
          var saveFile = File(Path +"/"+Name+"_80.png");
          sfwPNG24(saveFile);
          doc.resizeImage(50, undefined, undefined, ResampleMethod.BICUBICSHARPER);
          var saveFile = File(Path +"/"+Name+"_50.png");
          sfwPNG24(saveFile);
          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
          app.preferences.rulerUnits = startRulerUnits;
          }
          function sfwPNG24(saveFile){
          var pngOpts = new ExportOptionsSaveForWeb; 
          pngOpts.format = SaveDocumentType.PNG
          pngOpts.PNG8 = false; 
          pngOpts.transparency = true; 
          pngOpts.interlaced = false; 
          pngOpts.quality = 70;
          activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts); 
          }
          
          
          • 2. Re: multiple images batch resize and rename
            strife_quio Level 1

            holy crap!! THANK YOU. you just saved me hours of work. I'll try it out later but it looks good

            • 3. Re: multiple images batch resize and rename
              strife_quio Level 1

              ok that works great. now im trying to figure out how to have the script put the out put files into a sub folder "web". And with this script is it possible to put in a droplet or run in bridge?

              • 4. Re: multiple images batch resize and rename
                Paul Riggott Level 6

                What you can do is create an action that calls the script using "Insert Menu Item" from the Action Palette flyout menu

                Once this has been created you can then use Batch from Bridge.

                 

                Here is the modified code that wll place the files into the web folder....

                 

                #target photoshop
                main();
                function main(){
                if(!documents.length) return;
                app.displayDialogs = DialogModes.NO;
                var startRulerUnits = app.preferences.rulerUnits;
                app.preferences.rulerUnits = Units.PIXELS;
                var doc = app.activeDocument;
                var Name = doc.name.replace(/\.[^\.]+$/, '');
                var originalPath = decodeURI(doc.path);
                var Path = Folder(originalPath +"/Web");
                if(!Path.exists) Path.create();
                doc.resizeImage(600, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                var saveFile = File(Path +"/"+Name+"_600.png");
                sfwPNG24(saveFile);
                doc.resizeImage(400, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                var saveFile = File(Path +"/"+Name+"_400.png");
                sfwPNG24(saveFile);
                doc.resizeImage(250, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                var saveFile = File(Path +"/"+Name+"_250.png");
                sfwPNG24(saveFile);
                doc.resizeImage(150, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                var saveFile = File(Path +"/"+Name+"_150.png");
                sfwPNG24(saveFile);
                doc.resizeImage(100, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                var saveFile = File(Path +"/"+Name+"_100.png");
                sfwPNG24(saveFile);
                doc.resizeImage(80, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                var saveFile = File(Path +"/"+Name+"_80.png");
                sfwPNG24(saveFile);
                doc.resizeImage(50, undefined, undefined, ResampleMethod.BICUBICSHARPER);
                var saveFile = File(Path +"/"+Name+"_50.png");
                sfwPNG24(saveFile);
                app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
                app.preferences.rulerUnits = startRulerUnits;
                }
                function sfwPNG24(saveFile){
                var pngOpts = new ExportOptionsSaveForWeb; 
                pngOpts.format = SaveDocumentType.PNG
                pngOpts.PNG8 = false; 
                pngOpts.transparency = true; 
                pngOpts.interlaced = false; 
                pngOpts.quality = 70;
                activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts); 
                }
                
                
                • 5. Re: multiple images batch resize and rename
                  strife_quio Level 1

                  ok so itried it and it dosnt seem to making a new folder and puting the new files into it, even tried to make it be fore running it

                  • 6. Re: multiple images batch resize and rename
                    Paul Riggott Level 6

                    Were you using a document that had not been saved? If so there would be no Path.

                    I have just tested it again and the folder is created if it did not exist.

                    • 7. Re: multiple images batch resize and rename
                      strife_quio Level 1

                      yea its saved. open folder, then open image with photoshop (right-click) run script. oh and would it matter if it is server side?

                      • 8. Re: multiple images batch resize and rename
                        Paul Riggott Level 6

                        There can be problems when using servers, the only thing you could try is running the code from ExtendScript Toolkit and see if any error show up.

                        This is one reason Adobe doesn't support network saving etc.