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

How can I automate a batch crop and straighten function on single pics?

New Here ,
Dec 22, 2008 Dec 22, 2008

Copy link to clipboard

Copied

Here's my problem. I have to shoot thousands of pics of baseball cards. The cards are of varying sizes but they're rectangular in shape. I need to crop out the background (black velvet) and maybe straighten the images (depending on how close I can get the images straight when I shoot them)

PS has a nice command that will automatically crop and straighten pics that have been scanned. I've tried to run this command on my single pics and it works fine, except that I also get two additional crops/pics of stray hairs on the black background. I've also tried to make an action that I can turn into a batch or droplet and run on all the pics. I've not had much success. I'll end up with pics of stray hairs and not the card. I then have to go and manually delete the stray pics. Too much work.

Is there any way I can automate the process of cropping, straightening the pics then saving then new version?

Thanks
TOPICS
Actions and scripting

Views

44.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

correct answers 1 Correct answer

Valorous Hero , May 28, 2011 May 28, 2011

I think this was the script....

#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[a] instanceof File) {
			var doc = open(fileList[a]);
			doc.flatten();
			var docname = doc.name.slice(0
...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

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 27, 2011 May 27, 2011

Copy link to clipboard

Copied

Hi Paul, looking for the article from the link you posted (http://www.adobeforums.com/webx/.59b7368d/5)

but it takes me to the forum home page (http://forums.adobe.com/index.jspa)

Could you give me some keywords or the topic so I can find it?

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 ,
May 28, 2011 May 28, 2011

Copy link to clipboard

Copied

I think this was the script....

#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[a] instanceof File) {
			var doc = open(fileList[a]);
			doc.flatten();
			var docname = doc.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;
};

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
Community Beginner ,
Sep 05, 2011 Sep 05, 2011

Copy link to clipboard

Copied

Thank you, thank you, thank you.

You just saved me about 90 minutes worth of work by reposting this script.  I followed your directions and I'm now watching Photoshop fly through a batch crop and straighten process for about 60 "gang scanned" images.

I really appreciate the help.

Cheers,

AJ

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
Community Expert ,
May 28, 2011 May 28, 2011

Copy link to clipboard

Copied

I do not know why this append is here in an old thread on batch crop and straightening images for baseball cards. If this append has anything to do with something like a composit thing a baseball card, mag cover etc. An other way to address the problem is to batch populate a Photo Collage Template that will auto size and place in images into a template and leave the populated collage as a PSD file so that it can be tweaked. ie Straighten image add anotation change position etc. My Photoshop Photo Collage Toolkit is designed to do just that. In fact is comes with a sample Baseball Template and Mag Cover template.  The sample Basball Template has many groups and  hidden layers that let you change things like Logos, Frame, Field position etc. Example: Babe Ruth Card.jpg and JJMackTime.jpg

 

Documentation and download: Free Photoshop Photo Collage and Mockup Toolkit

JJMack

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

Thanks Paul, I appreciate the help but two issues with that. The instructions are for someone who has scanned multiple images and wants to separate them. I have one image that I need to separate from the background.

The second issue is what the heck do I do with the code? I'm not a programmer or even a good PS user so the code is meaningless to me. Do I copy and paste it somewhere??

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

The code will work if there are multiple images or just one.
All it means is that it will automate doing a folder of documents.
All the new extracted documents are save in a folder called "Edited" off the selected folder.

Photoshop JavaScripts are saved useing a text editor or better still Photoshop editing environment "Adobe ExtendScript Toolkit" this get installed at the same time as Photoshop. Copy the code and paste it into a new "ExtendScript Toolkit" document the save it to the relevant folder.
PS7 and PSCS are saved with an "js" extension and PS2/3/4 are saved with a "jsx" extension.
The normal place to save the scripts is:
PC:- C:/Program Files/Adobe/Adobe Photoshop CS#/Presets/Scripts/
Mac:- [hard drive]/Applications/Adobe Photoshop CS#/Presets/Scripts/
Allthough they can be saved anywhere you like.
To run a script:
File - Scripts (select script) (if placed in above folders) or
File - Scripts - Browse (to where ever you saved the 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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

Thanks Paul, sorry to be such a noob at this but I can't find the "ExtendScript Toolkit" document needed to create the document. I have a folder called "Scripting guide" that contains sample scripts and a Utility folder which contains a "ScriptingListener" plugin but that's it. I'm still struggling with this.

I really appreciate your help.

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

You would normally find it here:-
C:\Program Files\Adobe\Adobe Utilities
CS3 and CS4 there should be shortcuts existing under Start - Programs

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

I've got CS3 and I'm mac based.

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

On my mac it can be found here:-
Applications - Utilities - Adobe Utilities - "ExtendScript Toolkit 2"

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

Got it! 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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

When I opened it, I got three files, *source1, javascript console and data brower. Do I simply copy and paste the code into the *source1 box?

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

Yes, then save it with any name you like.

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 ,
Dec 23, 2008 Dec 23, 2008

Copy link to clipboard

Copied

Thanks Paul,

I figured it out right before you posted. The script works quite well! I just have to delete the un-necessary pics that I get. The script is taking each photo and spitting out three copies, one with the crop I need and two smaller ones with cropped shots of hair that was on my black background. I guess when I shoot the next batch of pics, I'll use a clean, white background instead.

thanks again for all your help!!!

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 ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

cropAndStraightenBatch.jsx

 

Script on GitHub.  Save script in text editor as .jsx file. 

Do not place .jsx file in folder with "RUN" scanned photos. 

Do NOT place "OUTPUT" folder in folder with RUN scanned photos.  

Open Photoshop

Go to FILE / SCRIPTS / BROWSE

Select the .jsx file.

You will see popup boxes with instructions in small print at op of box instructing you to make selections.

Wait and watch for the magic to happen.

 

 

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 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

LATEST

Perfect.

 

Only nitpick - the recursion just document that the output folder should not be a sub-folder of the source - otherwise you get in a recursive loop.

 

My project went from weeks to days with this i think.

 

Truly, truly appreciated.

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