Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

Batch Crop & Straighten

$
0
0

A while ago a good chap helped me out by creating a script that prompted the user for a folder, then ran the Crop and Straighten Photos command on all images contained in the folder and saved the newly created photos in a new folder.  The script is below.

 

The script saves cropped photos as PNGs, I'd like to save them as JPEG.  Could someone help me out by tweaking the script to save as JPEG?  I'd like them saved with the highest quality option.

 

#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){     var fileList = inFolder.getFiles(/\.(jpg|tif|png|)$/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) + ".png");                    SavePNG(saveFile);                    activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;                    count++;               }          }     }
};

function CropStraighten() {
     function cTID(s) { return app.charIDToTypeID(s); };     function sTID(s) { return app.stringIDToTypeID(s); };     executeAction( sTID('CropPhotosAuto0001'), undefined, DialogModes.NO );
};

function SavePNG(saveFile){
    pngSaveOptions = new PNGSaveOptions();    pngSaveOptions.embedColorProfile = true;    pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;    pngSaveOptions.matte = MatteType.NONE;    pngSaveOptions.quality = 1;     pngSaveOptions.PNG8 = false; //24 bit PNG    pngSaveOptions.transparency = true;     activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}

function zeroPad(n, s) {
     n = n.toString();     while (n.length < s) n = '0' + n;     return n;
};

Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>