Skip to main content
Participant
October 16, 2011
Question

Need to automate loading subfolders into stacks + action

  • October 16, 2011
  • 1 reply
  • 1300 views

Hi,

I've never really used scripts in photoshop, and have been browsing the forums without really understanding much, but would appreciate some help getting underway.

What I need to do is find a way to moved through subfolders, each has a number of images I'd like to load in a stack, align and blend and then save the result as a jpeg. If the filename could be based on the subfolder name that would be great.

I'm using CS5 on a Mac.

thanks,

Danny.

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
October 16, 2011

Could you please give a list of the steps you want to take (with the exact menu-items’ names) and just to make sure also a screenshot of the folder-structure?

And do you really want to destroy the layered file and only keep a jpg? Because that might be less than ideal if the result should need tweaking.

Participant
October 16, 2011

Thanks.

  So my root folder here is called "hoxton" and each datestamped folder has 5 images.

For each dated folder I want to load its images into a stack, auto-align layers, auto-blend layers and save a jpeg (quality 9). If it had a filename "foldername"_pano.jpg, that would let me keep them in order.

thanks.

Paul Riggott
Inspiring
October 16, 2011

You could give this a try...

#target photoshop
app.bringToFront();
var win = new Window( 'dialog', 'Auto Align and Blend' );
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.orientation='row';
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Auto-Align and Blend');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "row";
win.g5.alignment='left';
win.g5.spacing=10;
win.g5.st1 = win.g5.add('statictext',undefined,'Please select output folder...');
win.g10 =win.p1.add('group');
win.g10.orientation = "row";
win.g10.alignment='left';
win.g10.et1 = win.g10.add('edittext');
win.g10.et1.preferredSize=[350,20];
win.g10.et1.enabled=false;
win.g10.bu1 = win.g10.add('button',undefined,'Browse');
win.g10.bu1.onClick = function() {
  outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder !=null){
  win.g10.et1.text =  decodeURI(outputFolder.fsName);
  }
}
win.g15 =win.p1.add('group');
win.g15.orientation = "row";
win.g15.alignment='left';
win.g15.spacing=10;
win.g15.st1 = win.g15.add('statictext',undefined,'Please select top level folder...');
win.g20 =win.p1.add('group');
win.g20.orientation = "row";
win.g20.alignment='left';
win.g20.et1 = win.g20.add('edittext');
win.g20.et1.preferredSize=[350,20];
win.g20.et1.enabled=false;
win.g20.bu1 = win.g20.add('button',undefined,'Browse');
win.g20.bu1.onClick = function() {
  topLevelFolder = Folder.selectDialog("Please select the top level folder");
if(topLevelFolder !=null){
  win.g20.et1.text =  decodeURI(topLevelFolder.fsName);
  }
}
win.g200 =win.p1.add('group');
win.g200.orientation = "row";
win.g200.alignment='center';
win.g200.bu1 = win.g200.add('button',undefined,'Process');
win.g200.bu1.preferredSize=[220,30];
win.g200.bu2 = win.g200.add('button',undefined,'Cancel');
win.g200.bu2.preferredSize=[220,30];
win.g200.bu1.onClick=function(){
    if(win.g10.et1.text == ''){
        alert("No output folder has been selected!");
        return;
        }
    if(win.g20.et1.text == ''){
        alert("No top level folder has been selected!");
        return;
        }
    win.close(0);
var folders =[];
folders = FindAllFolders(topLevelFolder, folders);
folders.unshift(topLevelFolder);
for(var f in folders){
var PictureFiles = folders.getFiles(/\.(jpg|jpe|dng|bmp|tif|tiff|psd|crw|cr2|exr|pcx|nef|dcr|dc2|erf|raf|orf|tga|mos|pef|png)$/i);
  if(  PictureFiles.length < 3) continue;
  for(var p in PictureFiles){
      open(PictureFiles

);
      if(p > 0){
          try{activeDocument.mergeVisibleLayers();}catch(e){}
          activeDocument.activeLayer.duplicate(app.documents[0]);
          app.documents[1].close(SaveOptions.DONOTSAVECHANGES);
          }     
      }
        selectAllLayers();
       autoAlign();
       autoBlend();
  var saveFile = File (outputFolder +"/"+decodeURI(folders.name) + "_pano.jpg");
  SaveJPG(saveFile, 9);
  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }

}
win.center();
win.show();

function selectAllLayers(layer) {
if(layer == undefined) layer = 0;
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];
if(activeDocument.activeLayer.isBackgroundLayer) activeDocument.activeLayer.isBackgroundLayer = false;
var BL = activeDocument.activeLayer.name;
activeDocument.activeLayer = activeDocument.layers[layer];
    var desc5 = new ActionDescriptor();
        var ref3 = new ActionReference();
        ref3.putName( charIDToTypeID('Lyr '), BL);
    desc5.putReference( charIDToTypeID('null'), ref3 );
    desc5.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelectionContinuous') );
    desc5.putBoolean( charIDToTypeID('MkVs'), false );
    executeAction( charIDToTypeID('slct'), desc5, DialogModes.NO );
};
function autoAlign() {
    var desc16 = new ActionDescriptor();
        var ref8 = new ActionReference();
        ref8.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc16.putReference( charIDToTypeID('null'), ref8 );
    desc16.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('ADSt'), stringIDToTypeID('ADSContent') );
    desc16.putEnumerated( charIDToTypeID('Aply'), stringIDToTypeID('projection'), charIDToTypeID('Auto') );
    desc16.putBoolean( stringIDToTypeID('vignette'), false );
    desc16.putBoolean( stringIDToTypeID('radialDistort'), false );
    executeAction( charIDToTypeID('Algn'), desc16, DialogModes.NO );
};
function autoBlend() {
    var desc17 = new ActionDescriptor();
    desc17.putEnumerated( charIDToTypeID('Aply'), stringIDToTypeID('autoBlendType'), stringIDToTypeID('maxDOF') );
    desc17.putBoolean( charIDToTypeID('ClrC'), true );
    executeAction( stringIDToTypeID('mergeAlignedLayers'), desc17, DialogModes.NO );
};
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
  var fileFoldObj = fileFolderArray;
  if ( fileFoldObj instanceof File ) {  
  } else {
         destArray.push( Folder(fileFoldObj) );
  FindAllFolders( fileFoldObj.toString(), destArray );
  }
}
return destArray;

function SaveJPG(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);
}