Skip navigation
Currently Being Moderated

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

Dec 22, 2008 4:07 PM

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?

  • Currently Being Moderated
    Dec 23, 2008 12:13 AM   in reply to (jim_colman)
    Have a look here..
    Mark as:
  • Currently Being Moderated
    Dec 23, 2008 6:07 AM   in reply to (jim_colman)
    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.)
    Mark as:
  • Currently Being Moderated
    Dec 23, 2008 8:12 AM   in reply to (jim_colman)
    You would normally find it here:-
    C:\Program Files\Adobe\Adobe Utilities
    CS3 and CS4 there should be shortcuts existing under Start - Programs
    Mark as:
  • Currently Being Moderated
    Dec 23, 2008 8:31 AM   in reply to (jim_colman)
    On my mac it can be found here:-
    Applications - Utilities - Adobe Utilities - "ExtendScript Toolkit 2"
    Mark as:
  • Currently Being Moderated
    Dec 23, 2008 8:53 AM   in reply to (jim_colman)
    Yes, then save it with any name you like.
    Mark as:
  • Currently Being Moderated
    May 27, 2011 5:30 PM   in reply to Paul Riggott

    Hi Paul, looking for the article from the link you posted (

    but it takes me to the forum home page (

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

    Mark as:
  • Currently Being Moderated
    May 28, 2011 1:06 AM   in reply to mjjwang

    I think this was the script....


    #target Photoshop
    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]);
    var docname = fileList[a].name.slice(0,-4);
    var count = 1;
    var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".jpg");
    SaveJPEG(saveFile, 12);
    activeDocument.close(SaveOptions.DONOTSAVECHANGES) ; 
    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; 
    Mark as:
  • JJMack
    5,969 posts
    Jan 9, 2006
    Currently Being Moderated
    May 28, 2011 3:17 AM   in reply to mjjwang

    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:



    Documentation amd download

    Mark as:
  • Currently Being Moderated
    Sep 5, 2011 5:49 AM   in reply to Paul Riggott

    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.






    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)