Skip to main content
Known Participant
July 9, 2014
Question

change save to jpg to tiff

  • July 9, 2014
  • 1 reply
  • 980 views

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 instanceof File){ 

var doc= open(fileList); 

doc.flatten(); 

var docname = fileList.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;  

}; 

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
July 9, 2014

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.

hhost05Author
Known Participant
July 9, 2014

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?

hhost05Author
Known Participant
July 9, 2014

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?