• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

scripting and Crop and Straighten photos

New Here ,
May 18, 2008 May 18, 2008

Copy link to clipboard

Copied

photoshop CS3 has this neat feature "Crop and Straighten photos" which is very helpful in cleaning up scanned images (remove the black border) but is there a way to turn it into an action ?

i would like to apply this against many images (lots of files) in an automated way but being new to scripts/actions, I haven't had much success since this command creates a copy of the original.

is there an action that will help me batch remove the black border from all my images either using this CS3 command or another. thanks
TOPICS
Actions and scripting

Views

4.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Valorous Hero ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

Yes this should do the job, have all your pics in one folder and run this script. It looks for jpg, psd and tif in that folder, creates a folder of the sected folder called edited and puts the croped picures in there. Your scan can have mulitple areas. The output files are in tif format.
Save the code as FileName.jsx and to run File - Scripts - Browse to where you saved the file.
Paul.
/////////////////////////////////////////


#target Photoshop

app.bringToFront;

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

if(inFolder != null){

var fileList = inFolder.getFiles(/\.(jpg|tif||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;

whi...



















































Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 20, 2009 Jul 20, 2009

Copy link to clipboard

Copied

I sincerely apologize for the bump;

What sort of changes should be made to this script to allow for saving in JPEG format instead of TIFF?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 21, 2009 Jul 21, 2009

Copy link to clipboard

Copied

LATEST

This should do it..

#target Photoshop
app.bringToFront;
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){
var fileList = inFolder.getFiles(/\.(jpg|tif||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....























Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

Thank you very much Paul. it worked like a charm... exactly what I was looking for. i thought maybe there was an easier way than a script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 06, 2008 Jul 06, 2008

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2008 Jul 17, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2008 Jul 19, 2008

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 19, 2008 Jul 19, 2008

Copy link to clipboard

Copied

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 instanceof File && fileList.name.match(/\.(jpg|tif||psd|)$/i)){
var doc= open(fileList
);
doc.flatten();
var docname = fileList
.name.slice(0,-4);
CropStraighten();
doc.close(SaveOptions.DONOTSAVECHANGES);
var count = 1;
...







instanceof Folder) {
// alert("Folder: " + fileList
);
ProcessFiles(fileList
)
}
else {
// inappropriate file type, or null
}
}
};

function CropStraighten() {
functi...
















Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines