Batch Crop & Straighten

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;

What a great script. I extended it to recurse through subdirectories, and to filter out images that are too small to be reasonable crops. I hope this helps someone else as much as the original helped me.
#target Photoshop
// This script recurses through a directory structure and saves straightened/cropped images to// a "StraightenedAndCropped" subfolder.// The function that does this tends to produce a lot of junk, so // this script also filters out images that aren't large enough to// be likely candidates.
// optional (for debugging)//$.level = 2//$.bp()
app.bringToFront;// you can use a folder selection dialogvar inFolder = Folder.selectDialog("Please select top-level folder to process");// or you can hard-code the folder if you like (making sure to escape the path in Windows)//var inFolder = new Folder("C:\\some\\folder");if(inFolder != null){    ProcessFolder(inFolder);};
function ProcessFolder(folder) {    // process any files here first    var fileList = folder.getFiles(/\.(jpg|tif|psd|)$/i);
    if (fileList.length > 0) {        // only create a subfolder etc. if we found anything        var outfolder = new Folder(decodeURI(folder) + "/StraightenedAndCropped");        // not sure whether the exists property refreshes on-demand so save an indicator of whether we created the folder        var created = false;        //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();                var originalWidth = doc.width;                var originalHeight = doc.height;                doc.close(SaveOptions.DONOTSAVECHANGES);                var count = 1;                while(app.documents.length){                    // if the width and  height of the derived image are not both at least 85% of both of the original dimensions,                    // do not save it at all                    if (activeDocument.width.value >= (originalWidth.value * .85)                    && activeDocument.height.value >= (originalHeight.value * .85)) {                        // create the output folder on demand                        if ((outfolder.exists == false) && !created) {                            outfolder.create();                            created = true;                        }                        var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".jpg");                        SaveJPEG(saveFile, 12);                        count++;                    }                    activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;                }            }        }    }
    // now go looking for new folders, and recurse into them (just don't recurse into our own folders)    var fileAndFolderList = folder.getFiles();    for (var i = 0; i < fileAndFolderList.length; i++){        if (fileAndFolderList[i] instanceof Folder && !endsWith(decodeURI(fileAndFolderList[i]), "StraightenedAndCropped")) {            ProcessFolder(fileAndFolderList[i]);        }    }};
// borrowed from http://stackoverflow.com/questions/280634/endswith-in-javascriptfunction endsWith(str, suffix) {    return str.indexOf(suffix, str.length - suffix.length) !== -1;}
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;};

Similar Messages

  • Batch Crop & Straighten Photos...? Please, Help.

    I have several hundred photos that have been scanned and they all need to be cropped and straightened. I have been unsuccessful in my attempts at being able to create and run a action or script to batch this automated feature in Photoshop CS4. Does anyone know how to accomplish this? Thanks.

    Here is a web site that looks like it will show you how to do it.  If not look at similar sites.
    http://www.webdesign.org/web/photoshop/tutorials/automate-crop-straighten-from-scans.3715. html

  • Need a script to batch automate "Crop & Straighten"

    So I have a few hundred image files that consist of 3 or 4 scanned photos also called "gang" scanned. The photoshop "Crop & Straighten" ability (located under File-->Automate) is great...But I want to be abe to run a script that will prompt me for a folder to be processed and then run the Crop & Straighten on all the photos, while saving them to another folder called "Edited" or something.  I found a script in the forums for this exact purpose, but it doesn't seem to work in CS5.  I ran it multiple times, it creates the folder "Edited" but nothing is inside of it. The script I found is posted below. Any ideas? I would really appreciate the help!
    #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 = 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) + ".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;

    Hi there,
    I have tested one script and encountered one problem; the script/PS is very aggressive. The result has been that single images have been divided to multiple images and many time "over cropped" and rotated in various degrees. Crazy : )
    Example Before/after:
    Dropbox - PS CROP&STRAIGHTEN
    Script used:
    Dropbox - CROPAndStraightenBatch.jsx
    I have about 3000 images that I would like to have cropped.
    What I would like to have is a script where I can state or set it to not allow it to divide pictures into many.
    Also...any script that can automate rotations as batch?
    Does this exist somewhere?
    Are there any scripts somewhere that I can test?
    Cheers
    Martin

  • Creating an action to crop straighten and save

    I have scanned in a hundred or so pages from old photo albums, and have a thousand or so more to save.
    I am hoping to use a batch process or script to automate the cropping/straightening & saving, but I can't work out how to get the files saved.
    The album pages do not have a fixed number of images, so the crop/straighten is creating a variable number of images  from 1 to 8 or 9 (maybe more - they are really old photos some of which which are very small).
    So I need to find a way to create an action to crop and straighten (the easy bit), and then to automate the saving without asking for a file name and path for each image - the names created in the crop process are fine.
    Can anyone help please.
    Many thanks

    There is free script which works just fine. Here is entire discussion http://forums.adobe.com/thread/290194. I tested script with Photoshop CC on WIndows and everything works perfect. Download, actually select all and copy from this page http://www.tranberry.com/photoshop/photoshop_scripting/PS4GeeksOrlando/IntroScripts/cropAn dStraightenBatch.jsx. Open text editor and paste then save as cropAndStraightenBatch.jsx file in Presets > Scripts folder or save on Desktop then copy and paste in mentioned folder. Run script from File > Scripts menu without any image open. In the first dialog navigate to folder with scanned photos then in second window navigate to folder where you want to save.

  • Crop & Straighten tool missing from Automate menu

    I'm using CS3, Extended
    The Crop & Straighten tool doesn't show up under the Automate menu.
    I've gone to Edit > Menus > Automate and it doesn't show up there either.
    I have quite a large amount of multiple scans that need to be cropped and separated.
    I never had this problem with CS2.
    The following are listed under the Automate menu:
    Batch
    PDF Create
    Create Droplet
    Pro Canvas (twice)
    Photo Tools Batch
    Photo Tools
    Conditional Mode Change
    Fit Image
    Merge to HDR
    Photo Merge
    I've tried opting for the no-show in the Edit > Menus thinking that there may be too many selections, but that didn't help. Also, like I said, Crop and Straighten doesn't show up there at all.
    Any help would be greatly appreciated.
    imjohn

    Is it hidden behind the Slice tool?   Any tools with a little triangle in the bottom right corner, have move tools behind them.
    You could use the keyboard short cut 'c', but if the Crop tool is hidden, keep pressing Shift c until you see it.

  • Batch Crop Error in Automator

    I am trying to batch crop about 100 photos using Automator. I drop the folder in and set my crop requirements however I am receiving a yellow triangle warning at the end of the work flow run saying that the crop images were "not supplied with the required data". I cannot figure out what the issue is.

    After the point where you've added the folder to the workflow, insert a Get Folder Contents action so that the workflow targets the files in the folder.  Typical workflow:
    Get Specified Finder Items (or equivalent)
    Get Folder Contents
    Crop Images

  • I am trying to batch crop in elements 9.

    When I select a folder from my desktop in browse for source under process multiple files none of the images are highlighted and a box comes up that folder is empty? I can't get them from my i-photo either? I have watched all the tutorials on batch cropping and it is not working.

    What type of images are in the source folder? Jpeg or raw etc.
    You can batch resize in Elements but you can only crop one image at a time. You need Lightroom 3 or CS5 for batch cropping.
    There are some free apps available. Try searching for batch crop jpegs.
     

  • Batch crop pdfs to the trim size

    I have hundreds of pdfs that include all printer marks (crop marks, color guide..etc..) and i want trim or crop these pdfs in order to remove these marks.  I want to end up with just the artwork itself with no printer marks. I also don't want to import into photoshop which will rasterize the content.  Surely, there must be an easy way inside Acrobat Pro to do this?  Haven't found it, though.  The crop tool just baffles me.  I know that in Acrobat Pro I can use the crop tool and draw a rectangle to crop to but what i want is to automatically crop to the trim marks or the artboard and then set it up as a batch.  Thanks for listening.
    -Mark

    Which version of Acrobat are you using? If 9 then there's no Crop Pages options anymore in the batch sequences. You will need a custom-made script to do it, like this one: http://try67.blogspot.com/2009/02/acrobat-batch-crop-pages.html
    Contact me by email if you're interested in it.  Otherwise you can just use the built-in function to crop the pages of multiple files.

  • I'm trying to do a batch crop in camera raw and there is no dropdown option in the crop tool to select inches or pixels. How can I fix this?

    I'm trying to do a batch crop in camera raw and there is no dropdown option in the crop tool to select inches or pixels. How can I fix this?

    Create an action to do the crop and user the image processor to batch process your RAW files and have it use your cropping action in the process.

  • Crop & Straighten photos problems

    Not sure if this can help anyone having problems using "Crop & Straighten photos"!
    I'm using CS3 (but I'm guessing the problem may exist in other versions) to try and subdivide a huge pile of old scanned prints. To make the job easier, I scanned with only 2 images on the platen so that there is plenty of white space around each image.
    When I try and apply the "Crop & Straighten photos" command, in almost every case it fails, only creating a duplicate image which looks ALMOST identical to the original. However if I then apply "Crop & Straighten photos" to that copy, it works perfectly.
    What I discovered is that my scanners (both HP models, a flat bed and an all-in-one) both create a scan with a fairly thick black edge on two sides of the image.
    So when I apply "Crop & Straighten photos", Photoshop thinks (quite correctly) that the image actually extends to the edge of the original scan, and there is therefore nothing to divide.
    The solution is to re-size the original image to 99%., and then apply "Crop & Straighten photos" and it works perfectly. So far 99% has worked on all the images I've tried, but it may need to be changed to 98 or lower in exceptional circumstances. Since the scanned photos are well away from the edges, there is no danger of cropping any of the originals scans, but be on the lookout just in case.
    Finally, I created an action to crop to 99% and save all the images (to a new directory), meaning I could automate that step, and then I used the script provided elsewhere in this forum to automate the "Crop & Straighten photos".
    Works a treat, and saves loads of time
    Colin

    Here is a web site that looks like it will show you how to do it.  If not look at similar sites.
    http://www.webdesign.org/web/photoshop/tutorials/automate-crop-straighten-from-scans.3715. html

  • Automating Photoshop's Crop & Straighten Tool

    Does anyone know of a way in which I can automate Photoshop's "Crop & Straighten" tool?
    I don't think this is as simple as simply creating an Action or a Droplet to perform this task, because running the "Crop & Straighten" tool on an image results in the creation of multiple new images, all of which need to be saved out at some point (either before running the tool again on a subsequent image; or before ending up with hundreds of new/unsaved images open at one time within Photoshop)...
    Any suggestions would be greatly appreciated... Thanks!

    Ok, If you want to try the above method here is the script.
    Run it when you have the layers created.
    #target photoshop
    if(documents.length){
    var docPath = activeDocument.path;
    var docName = activeDocument.name.slice(0,-4);
    var Directory = decodeURI(docPath+'/Edited');
    if(activeDocument.artLayers.length >1) CreateDirectory(Directory);
    for(var a=0;a<activeDocument.artLayers.length;a++){
       activeDocument.activeLayer = activeDocument.artLayers[a];
       if(!activeDocument.activeLayer.isBackgroundLayer){
             dupLayer("#"+(a+1));
             activeDocument.trim(TrimType.TRANSPARENT);
             //comment/uncomment SaveJPEG or SaveTIFF
             //SaveJPEG(File(Directory+"/"+docName+activeDocument.name+".jpg"), 10);
             SaveTIFF(File(Directory+"/"+docName+activeDocument.name+".tif"));
             activeDocument.close(SaveOptions.DONOTSAVECHANGES);
             activeDocument = documents[0];
    activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    function dupLayer(newName) {
        var desc111 = new ActionDescriptor();
            var ref52 = new ActionReference();
            ref52.putClass( charIDToTypeID('Dcmn') );
        desc111.putReference( charIDToTypeID('null'), ref52 );
        desc111.putString( charIDToTypeID('Nm  '), newName );
            var ref53 = new ActionReference();
            ref53.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
        desc111.putReference( charIDToTypeID('Usng'), ref53 );
        executeAction( charIDToTypeID('Mk  '), desc111, DialogModes.NO );
    function SaveJPEG(saveFile, jpegQuality){
    jpgSaveOptions = new JPEGSaveOptions();
    jpgSaveOptions.embedColorProfile = true;
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgSaveOptions.matte = MatteType.NONE;
    jpgSaveOptions.quality = jpegQuality; //1-12
    activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
    function SaveTIFF(saveFile){
    tiffSaveOptions = new TiffSaveOptions();
    tiffSaveOptions.embedColorProfile = true;
    tiffSaveOptions.alphaChannels = true;
    tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
    activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
    function CreateDirectory(Directory){
    var PathFold = new Folder(Directory);
    if (PathFold.exists == false) PathFold.create();

  • Crop Straighten and then Save

    I'm scanning a few thousand old family history photos and looking to minimize the manual input.
    My HP scanner software is not effective at splitting multiple photos, so I cannot use that option. I’m therefore scanning a page at a time containing “n” photos where n can be anything from 1 to say 12 (that’s the most I’ve had with sensible spacing between, using the very small images produced in the 1920’s).
    What I want to do next is to separate these pages into their individual images, if possible cropping and straightening at the same time. I accept that this will not be anything like 100% successful. Some have white borders, some have cream, some have none, others are filthy etc. But as I’m retaining the master scans, I can re-create any that are particularly bad.
    I have CS3 Extended, and Elements 5. So far I’ve tried each and they have pluses and minuses. At the moment I’m leaning towards CS3. I’ve created a simple action to crop and straighten which I’ve run in batch mode. Its doing a pretty good job of what I want. But I cannot find a way to automate the saving of the cropped images.
    I just want to get a jpg (quality 12).
    As the progs open a new image for each of the cropped images, I end up with up to 12 new images, cropped and resized and with nice new names which has the file name/number Plus Copy. But as new images, I do not know how to save them.
    Is it possible to automate this? If so how?
    Any suggestions welcome. I did google first, but as ever, there are so many responses that weeding out any possible correct answers is pretty near impossible.
    Thanks
    Colin

    I'm going to need to read a bit about this.
    I've read that post, and it seems as if theres a guy with exactly the same issue.
    I've never actually written a script before, so I'll need to read the manuals/books this weekend and give it and the image processor a try, to see if either suggestion will work in practice.
    I've created some test files, and I'll give it a try.
    I'll report progress in a few days.
    Thanks so far.
    Colin

  • Automate / Batch cropping 1000 images... not working properly

    Hi all,
    I may just be missing something here. If I open an image in photoshop and crop it, the image shows up at the new cropped size and I can then save the new image. I have 1000 people images with all different sizes but the same ratio. My hope is to create an action that crops a photo to a standard size and then saves into another folder.
    So I started my new action and did the crop and saved. Then I ran this action using automate and batch. The processing does happen but the images are cropped and then remain in a black box the size of the original photo. This is a problem for me... I only want to see the resized photo.
    Any idea where I'm going wrong?
    Thank you very much in advance
    Nelson Cardoso

    Curt Y wrote:
    How about using the Image Processor?  It should do that process.
    Select your images in Bridge and then click on Tools/photoshop/image processor.
    The image processor wll still need an action for it does not crop. The Image Processor also can not replace the original files.   If all images are the same size and aspect ratio to begin with it would be easy to create an action to do the crop.  Best done with the rectangle selection to and image crop.  Only those two steps would be needed in the adtion.  Once you have recorded the action it can batch. Set the batch dialog to process you folder of same size images and have it save over the original files or save in a new filder. No save is needed in the action.
    If images vary in size and aspect ratio you would need to some plugins or scripts in an action. You can download my crafting actions package it contains a couple of plug-in scripts that are useful for croping images.
    Crafting Actions Package
    Contains
    Action Actions Palette Tips.txt
    Action Creation Guidelines.txt
    Action Dealing with Image Size.txt
    Action Enhanced via Scripted Photoshop Functions.txt
    CraftedActions.atn Sample Action set includes an example Watermarking action
    Sample Actions.txt Photoshop CraftedActions set saved as a text file.
    12 Scripts for actions
    Download

  • Crop/ Straighten, but not both!

    Really weird: I straighten a photo. Then I want to crop it, but when I click the crop tool (after doing the straitening), ACR, un-straightens the image!
    I'ts like it's saying you can do one or the other, but not both.

    Rather than a rude answer to b2martin how about providing some useful information.  I read your original post, decided I couldn't tell whether you were describing your experience with the straightening tool, lens correction, or what.
    If you're using the straightening tool, it creates a crop containing the tilted image with boundaries all the way to the original image edge, at least in ACR hosted by Bridge/CS6.  Or maybe you're using Elements, can't really tell from your post.
    Richard Southworth

  • Grid when cropping & straightening

    Is there a way when cropping an image to view a grid overaid to help with these functions, especially with straightening?

    This is a feature.  When you use the Straighten Tool an orthogonal grid is superimposed on the Image as soon as you click on the Image and drag the mouse cursor.  When you use the slider or the value slider (that's what Apple calls the field with the number flanked by triangles), no grid is superimposed and you can see your Image "as is".
    You can activate the Straighten Tool in at least two ways: clicking the icon on the Tool Strip (that's what Apple calls the mini-toolbar in the bottom border of the Viewer), or clicking the tool icon at the top of the Straighten Brick.  When the tool is active, the mouse cursor changes to two equilateral triangles yoked together, one pointing up and one pointing down.
    All of this is covered well in the User Manual.
    Fwiw, Aperture distinguishes between "Tools" and "Brushes".  Afaict, this distinction is based on user expectation and not on logic.
    Message was edited by: Kirby Krieger -- clean up.

Maybe you are looking for