7 Replies Latest reply on Jul 27, 2014 5:18 AM by hhost05

    change save to jpg to tiff

    hhost05 Level 1

      I found a script that allows to crop and straighten scanned photos. However, there are 2 changes I want to make:

       

      (1) Instead of being saved as jpegs, I want to resulting files to be saved as tiff

       

      (2) Right now, it only looks at one level in a folder. I want it to dig into all subfolders as well. Is that possible?

       

      #target Photoshop 

      app.bringToFront; 

      var inFolder = Folder.selectDialog("Please select folder to process");  

      if(inFolder != null){ 

      var fileList = inFolder.getFiles(/\.(jpg|jpeg|png|tif|tiff|psd|)$/i); 

      var outfolder = new Folder(decodeURI(inFolder) + "/Edited"); 

      if (outfolder.exists == false) outfolder.create(); 

      for(var a = 0 ;a < fileList.length; a++){ 

      if(fileList[a] instanceof File){ 

      var doc= open(fileList[a]); 

      doc.flatten(); 

      var docname = fileList[a].name.slice(0,-4); 

      CropStraighten(); 

      doc.close(SaveOptions.DONOTSAVECHANGES);  

      var count = 1; 

      while(app.documents.length){ 

      var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".jpg"); 

      SaveJPEG(saveFile, 12); 

      activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;  

      count++; 

        } 

      }; 

      function CropStraighten() { 

      executeAction( stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO ); 

      }; 

      function SaveJPEG(saveFile, jpegQuality){ 

      jpgSaveOptions = new JPEGSaveOptions(); 

      jpgSaveOptions.embedColorProfile = true; 

      jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 

      jpgSaveOptions.matte = MatteType.NONE; 

      jpgSaveOptions.quality = jpegQuality;  

      activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE); 

      function zeroPad(n, s) {  

      n = n.toString();  

      while (n.length < s) n = '0' + n;  

      return n;  

      }; 

        • 1. Re: change save to jpg to tiff
          c.pfaffenbichler Level 9

          1) Here is an example that should show how to save a tif file.

          function saveCopyAsTif (myDocument, thePath) {

          // tif options;

          tifOpts = new TiffSaveOptions();

          tifOpts.embedColorProfile = true;

          tifOpts.imageCompression = TIFFEncoding.TIFFLZW;

          tifOpts.alphaChannels = false;

          tifOpts.byteOrder = ByteOrder.MACOS;

          tifOpts.layers = false;

          // save copy;

          myDocument.saveAs((new File(thePath)), tifOpts, true);

          };

           

          2) It’s possible.

          • 2. Re: change save to jpg to tiff
            hhost05 Level 1

            c.pfaffenbichler wrote:

             

            1) Here is an example that should show how to save a tif file.

            function saveCopyAsTif (myDocument, thePath) {

            // tif options;

            tifOpts = new TiffSaveOptions();

            tifOpts.embedColorProfile = true;

            tifOpts.imageCompression = TIFFEncoding.TIFFLZW;

            tifOpts.alphaChannels = false;

            tifOpts.byteOrder = ByteOrder.MACOS;

            tifOpts.layers = false;

            // save copy;

            myDocument.saveAs((new File(thePath)), tifOpts, true);

            };

             

            2) It’s possible.

             

            Thanks for the answer. How is the 2nd part possible?

            • 3. Re: change save to jpg to tiff
              hhost05 Level 1

              hhost05 wrote:

               

              c.pfaffenbichler wrote:

               

              1) Here is an example that should show how to save a tif file.

              function saveCopyAsTif (myDocument, thePath) {

              // tif options;

              tifOpts = new TiffSaveOptions();

              tifOpts.embedColorProfile = true;

              tifOpts.imageCompression = TIFFEncoding.TIFFLZW;

              tifOpts.alphaChannels = false;

              tifOpts.byteOrder = ByteOrder.MACOS;

              tifOpts.layers = false;

              // save copy;

              myDocument.saveAs((new File(thePath)), tifOpts, true);

              };

               

              2) It’s possible.

               

              Thanks for the answer. How is the 2nd part possible?

               

               

              Thanks a lot for the answer!! How is the 2nd part possible?

              • 4. Re: change save to jpg to tiff
                c.pfaffenbichler Level 9
                How is the 2nd part possible?

                Please try this (and adapt it as necessary):

                var sourceFolder = Folder.selectDialog("Select folder");

                var items = retrieveFiles(sourceFolder, []);

                alert (items.join("\n"));

                ////// get from subfolders //////

                function retrieveFiles (theFolder, theFiles) {

                  if (!theFiles) {var theFiles = []};

                  var theContent = theFolder.getFiles();

                  for (var n = 0; n < theContent.length; n++) {

                  var theObject = theContent[n];

                  if (theObject.constructor.name == "Folder") {

                  theFiles = retrieveFiles(theObject, theFiles)

                  };

                  if (theObject.name.match(new RegExp(/\.(jpe|jpg|jpeg|gif|png|tif|tiff|bmp|psd|dng|pict|eps|raw|rw2|crw|cr2)/i)) != null) {

                  theFiles = theFiles.concat(theObject)

                  }

                  };

                  return theFiles

                  };

                • 5. Re: change save to jpg to tiff
                  hhost05 Level 1

                  sorry, i'm a bit new to this. can you embed this new code into the previous script I posted?

                  • 6. Re: change save to jpg to tiff
                    c.pfaffenbichler Level 9

                    Please try this:

                    // 2014 , use it at your own risk;

                    #target Photoshop

                    app.bringToFront;

                    var inFolder = Folder.selectDialog("Please select folder to process"); 

                    if(inFolder != null){

                    var fileList = retrieveFiles (inFolder, []);

                    var outfolder = new Folder(decodeURI(inFolder) + "/Edited");

                    if (outfolder.exists == false) outfolder.create();

                    for(var a = 0 ;a < fileList.length; a++){

                    if(fileList[a] instanceof File){

                    var doc= open(fileList[a]);

                    doc.flatten();

                    var docname = fileList[a].name.slice(0,-4);

                    CropStraighten();

                    doc.close(SaveOptions.DONOTSAVECHANGES); 

                    var count = 1;

                    while(app.documents.length){

                    var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".tif");

                    saveCopyAsTif(app.activeDocument, saveFile);

                    activeDocument.close(SaveOptions.DONOTSAVECHANGES) ; 

                    count++;

                      }

                    }

                    }

                    };

                    //////

                    function CropStraighten() {

                    executeAction( stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO );

                    };

                    ////// get from subfolders //////

                    function retrieveFiles (theFolder, theFiles) {

                      if (!theFiles) {var theFiles = []};

                      var theContent = theFolder.getFiles();

                      for (var n = 0; n < theContent.length; n++) {

                      var theObject = theContent[n];

                      if (theObject.constructor.name == "Folder") {

                      theFiles = retrieveFiles(theObject, theFiles)

                      };

                      if (theObject.name.match(new RegExp(/\.(jpg|jpeg|png|tif|tiff|psd)/i)) != null) {

                      theFiles = theFiles.concat(theObject)

                      }

                      };

                      return theFiles

                      };

                    //////

                    function saveCopyAsTif (myDocument, thePath) {

                    // tif options;

                    tifOpts = new TiffSaveOptions();

                    tifOpts.embedColorProfile = true;

                    tifOpts.imageCompression = TIFFEncoding.TIFFLZW;

                    tifOpts.alphaChannels = false;

                    tifOpts.byteOrder = ByteOrder.MACOS;

                    tifOpts.layers = false;

                    // save copy;

                    myDocument.saveAs((new File(thePath)), tifOpts, true);

                    };

                    //////

                    function SaveJPEG(saveFile, jpegQuality){

                    jpgSaveOptions = new JPEGSaveOptions();

                    jpgSaveOptions.embedColorProfile = true;

                    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

                    jpgSaveOptions.matte = MatteType.NONE;

                    jpgSaveOptions.quality = jpegQuality; 

                    activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);

                    }

                    //////

                    function zeroPad(n, s) { 

                    n = n.toString(); 

                    while (n.length < s) n = '0' + n; 

                    return n; 

                    };

                    • 7. Re: change save to jpg to tiff
                      hhost05 Level 1

                      thank you so much! This works great!

                       

                       

                      Are there options when saving as tiff like there is with saving as jpg?