If you frequently shoot panoramas and stitch the photos together using Photoshop’s brilliant Photomerge script, and you often have to stitch together more sets of photos, you may get the ‘Repeated-Open-File-Dialog-Stress-Disorder’ and boredom will soon appear. I have managed to find a script to ‘automate-the-automation’ that works with multiple folders (each folder containing your individual shots).

So, this is the setup:


…you get the idea.

Now, this script will dig down in each of these folders (you have to supply the starting folder when you run it — ie. the folder CONTAINING Folder1 and Folder2), and then it will read the files and blend/stitch/vignette, you name it, and save the file in each of the respective folders as ‘Stitch.psd’. Sweet, eh? Enjoy and thanks to the smart dudes at www.ps-scripts.com for this immense time-saver (now I can leave it running overnight and in the morning, all panoramas are stitched!).

And here’s the script (paste this in Adobe’s ExtendScript Editor thingy). Make sure you customize the includepath to the Scripts folder to your installation and also uncomment the desired alignmentKey for your situation:

[sourcecode language=”plain”]
var runphotomergeFromScript = true; // must be before Photomerge include
// @includepath “/c/Program Files/Adobe/Adobe Photoshop CS4 (64 Bit)/Presets/Scripts/”
// @include “Photomerge.jsx”
// @show include
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
var workFolder = Folder.selectDialog();
var folders = workFolder.getFiles( function( file ) { return file instanceof Folder; } );
for( var i = 0; i < folders.length; i++ ) { var folder = folders[i]; var fList = folder.getFiles( '*.jpg' ); // override Photomerge.jsx settings. Default is "Auto". Uncomment to override the default. //photomerge.alignmentKey   = "Auto"; //photomerge.alignmentKey   = "Prsp"; photomerge.alignmentKey   = "cylindrical"; //photomerge.alignmentKey   = "spherical"; //photomerge.alignmentKey   = "sceneCollage"; //photomerge.alignmentKey   = "translation"; // "Reposition" in layout dialog // other setting that may need to be changed. Defaults below photomerge.advancedBlending      = true; // 'Bend Images Together' checkbox in dialog photomerge.lensCorrection      = false; // Geometric Distortion Correction'checkbox in dialog photomerge.removeVignette      = true; // 'Vignette Removal' checkbox in dialog if( fList.length > 1 )
// The merged doc will be the activeDocument
activeDocument.saveAs( new File( fList[0].parent + ‘/Stitch.psd’ ) , psdOpts, true, Extension.LOWERCASE);
activeDocument.close( SaveOptions.DONOTSAVECHANGES );

The above script works fine, as long as you don’t need to save files that go beyond the PSD size limitation. The Large Document Format (PSB) supports documents up to 300,000 pixels in any dimension. All Photoshop features, such as layers, effects, and filters, are supported by the PSB format. Currently, if you save a document in PSB format, it can only be opened in Photoshop CS. Other applications and older versions of Photoshop cannot open documents saved in PSB format. Note: Most other applications and older versions of Photoshop cannot support documents with file sizes larger than 2 GB.
A modification to the above script is required. Instead of the line where it reads: activeDocument.SaveAs(….) use the following script:

savePSB(fList[0].parent + ‘/Stitch.psb’);

… and then add, at the end of the script, the following function:

function savePSB(fileNameAndPath)
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

var desc19 = new ActionDescriptor();
var desc20 = new ActionDescriptor();
desc20.putBoolean( sTID(‘maximizeCompatibility’), true );
desc19.putObject( cTID(‘As ‘), cTID(‘Pht8’), desc20 );
desc19.putPath( cTID(‘In ‘), new File( fileNameAndPath ) );
desc19.putBoolean( cTID(‘LwCs’), true );
executeAction( cTID(‘save’), desc19, DialogModes.NO );

This should allow saving to PSB automatically. Since there’s no function to save to PSB directly, the savePSB function was necessary.
To make things easier, you can download the full version of the script, with PSB enabled from the link below:

Download BatchMerge.jsx

Hope you like this script, please leave any comments below. If this script saved you as much time as it saved me, maybe you would consider making a small donation towards coffee an such? Use the PayPal button below if you wish to donate: