Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: scripting and Crop and Straighten photos

233 views
Skip to first unread message

funky...@adobeforums.com

unread,
Jul 7, 2008, 12:10:09 AM7/7/08
to
This is an insightful approach to overcoming the new file that is created when running the "Crop and Straighten Photos" command. Thank you for sharing!

When running that command (from the file menu; not from the script) on a single scanned image, Photoshop will sometimes think it has found multiple images if the photo contains objects with "edges." To overcome this, you can hold down the "Alt" key (Windows) when selecting the command, thereby telling Photoshop that you are working with only one photo. (See the tip at <http://livedocs.adobe.com/en_US/Photoshop/10.0/help.html?content=WSfd1234e1c4b69f30ea53e41001031ab64-762e.html.)> Unfortunately, this "Alt" key option is not captured when recording an action. Is there any way to incorporate this into the script provided here?

Thanks!

sic...@adobeforums.com

unread,
Jul 17, 2008, 7:50:55 AM7/17/08
to
Hi funkydoobi. A very crude fix for your problem that has worked for me is (assuming you are doing an automated batch with this action) to hold down the alt key as you select the batch option, click ok, and keep holding it down throughout the running of the batch. It seems that as Photoshop calls up the Crop & Straighten Filter every time it goes through the action, the constantly held down alt key tells it that it is a single photo. However, if you lift up on the alt key at all, it goes back to its multiple image cropping. I just use a heavy object to keep the alt key held down and walk away. It would be nice to not have to have that held down all the time, and have something in the above script tell the filter that it is a single photo in the image. Anyone else have a solution?

funky...@adobeforums.com

unread,
Jul 19, 2008, 6:53:38 PM7/19/08
to
Einstein once said, "Make everything as simple as possible, but not simpler."

Here I am, looking for a complicated scripting solution, when the easy solution is right in front of me. This solution is brilliant!

I will try it tonight.

Thank you!

funky...@adobeforums.com

unread,
Jul 20, 2008, 12:45:19 AM7/20/08
to
OK, I'm giving back: here's an adaptation of Paul's script that uses recursion to iterate through all subdirectories. (Note that I also changed the file name suffix to a "static" (non-sequenced) value, as well as the name of the output folder, since I am using this to process single-photo image files. The original lines are commented out.) To implement the recursion, I defined the "main" functionality in a function ("ProcessFiles") that calls itself when encountering a subfolder.

Here's the full script. Hope this helps someone!
===========================

// Prompts the user for a directory, and then recursively processes each image
// in that directory and all subdirectories by executing the "Crop and
// Straighten" command. Images are saved with a specified suffix in a
// designated subfolder.

// Adapted from a script provided by "Paul R." in the "Photoshop Scripting" forum
// <http://www.adobeforums.com/webx?7@@.59b54905/2>

// TIP: Hold down the "Alt" key while running this script to instruct Photoshop
// to treat the image as a single photo. (For more information, see:
// <http://livedocs.adobe.com/en_US/Photoshop/10.0/help.html?content=WSfd1234e1c4b69f30ea53e41001031ab64-762e.html)>

#target Photoshop
app.bringToFront;
var inputFolder = Folder.selectDialog("Please select folder to process");
if(inputFolder != null){
ProcessFiles(inputFolder);
};

function ProcessFiles(inFolder) {
// var fileList = inFolder.getFiles(/\.(jpg|tif||psd|)$/i);
var fileList = inFolder.getFiles();
var outfolder = new Folder(decodeURI(inFolder) + "/Cropped");
if (outfolder.exists == false) outfolder.create();
for(var a = 0 ;a < fileList.length; a++){ if(fileList[a] instanceof File && fileList[a].name.match(/\.(jpg|tif||psd|)$/i)){ 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"); var saveFile = new File(decodeURI(outfolder) + "/" + docname + "-CR"+ ".tif"); SaveTIFF(saveFile); activeDocument.close(SaveOptions.DONOTSAVECHANGES) ; count++; } } else if (fileList[a] instanceof Folder) { // alert("Folder: " + fileList[a]); ProcessFiles(fileList[a]) } else { // inappropriate file type, or null } } };

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

function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, false, Extension.LOWERCASE);
};

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

0 new messages