Stacking Groups of 3

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

sonyapaz

Stacking Groups of 3

Post by sonyapaz »

Hey, I'm a bit confused at the moment. Is there any reason the script you gave me would damage the quality of the pictures? On some photos it looks the same whether I use the script or do the layers and merge by hand, though usually a bit grainier.

On many of the pictures though, the red is much too high and the photo has that xeroxed effect; just generally deteriorated. I've tried to follow what the script does differently, but I don't understand the script itself and can't follow the history well as it runs quickly.

By hand, I am doing the following.

Open 3 files with the "Load into stacks" script, make sure they are in the correct layer order, setting the red to 40% opacity, green to 50%, auto levels on each layer, merge, then auto levels again. The links below are an example of what I get from the script and what I get by hand.

http://img48.imageshack.us/i/rgbbyscript.jpg/
http://img690.imageshack.us/i/rgbbyhand.jpg/

Sorry to bother you again, but having this working better would help me greatly.
Paul MR

Stacking Groups of 3

Post by Paul MR »

I have just had another look and there seems to be an anomaly between Photoshop versions.
CS3 Does run AutoLevels but CS4 runs Auto Tone! using the same command, I wonder if this is causing the problem?
You can do a test with this code, please use only three files in a new folder, this will not do the merge or save the files so that you can check the history and the layers.
Code: Select all#target photoshop
main();
function main(){
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,500,280],"+
"panel0:Panel{bounds:[10,10,390,170] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[80,10,290,40] , text:'Stack Files' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,50,370,120] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"folder:EditText{bounds:[10,10,300,30] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"browse:Button{bounds:[310,10,351,31] , text:'<<' },"+
"fileCount:DropDownList{bounds:[240,40,346,60]},"+
"statictext1:StaticText{bounds:[10,40,230,60] , text:'Number of files to stack...' ,properties:{scrolling:undefined,multiline:undefined}}},"+
"process:Button{bounds:[10,130,180,151] , text:'Process' },"+
"button2:Button{bounds:[200,130,370,151] , text:'Cancel' }}};"
var win = new Window(dlg,'Stack Files');
win.panel0.panel1.folder.enabled=false;
win.panel0.title.graphics.font = ScriptUI.newFont("Arial","BOLDITALIC",26);
for(var a = 2;a<21;a++){
    win.panel0.panel1.fileCount.add('item',a);
    }
win.panel0.panel1.fileCount.selection=1;
win.panel0.panel1.browse.onClick = function(){
inputFolder = Folder.selectDialog("Please select the folder with Files to process");   
   if(inputFolder !=null){
      win.panel0.panel1.folder.text =  decodeURI(inputFolder.fsName);
      }
}
win.panel0.process.onClick = function(){
    if(win.panel0.panel1.folder.text ==''){
            alert("No input folder has been selected!");
            return;
        }
    win.close(1);
    process();
    }
win.center();
win.show();
function process(){
   try{
DocsWritten=0;
DupDocs=0;
NoOfFilesToStack = win.panel0.panel1.fileCount.selection.index+2;
var newPath = Folder(decodeURI(inputFolder +"/Stacked"));
if(!newPath.exists) newPath.create();
var fileList = inputFolder.getFiles(/\.(jpg)$/i);
}catch(e){alert(e.line)}
if(fileList.length % NoOfFilesToStack) {
    alert("There are not multiples of " +NoOfFilesToStack+ "\n"+fileList.length+ " files exist");
    return;
    }
while(fileList.length){
    for(var a =0; a<NoOfFilesToStack;a++){
     try{
    app.open(fileList.shift());
    }catch(e){}
        }
    saveAll();
    }
alert("New Files Written = " + DocsWritten +"\nFiles That existed = "+ DupDocs);
function saveAll(){
try{
var Name = app.documents[0].name.replace(/\.[^\.]+$/, '');
for(var a = 1;a<documents.length;a++){
activeDocument=documents[a];
activeDocument.activeLayer.duplicate(documents[0]);
activeDocument = documents[0];
activeDocument.activeLayer.name=documents[a].name.replace(/\.[^\.]+$/, '');
}

}catch(e){}
var saveFile = File(newPath+"/"+Name+"-stack.psd");
var testFile  = File(newPath+"/"+Name+"-stack.psd");
if(testFile.exists){
     testFile.rename(testFile.name.slice(0,-4) + time() + ".psd");
     DupDocs++;
     }
if(NoOfFilesToStack == 3){
activeDocument.activeLayer=activeDocument.artLayers[1];
activeDocument.activeLayer.move(activeDocument.artLayers[0],  ElementPlacement.PLACEBEFORE);
activeDocument.artLayers[0].opacity=50;
activeDocument.artLayers[1].opacity=40;
activeDocument.activeLayer=activeDocument.artLayers[0];
activeDocument.activeLayer.autoLevels();
activeDocument.activeLayer=activeDocument.artLayers[1];
activeDocument.activeLayer.autoLevels();
activeDocument.activeLayer=activeDocument.artLayers[2];
activeDocument.activeLayer.autoLevels();
}
/*
activeDocument.mergeVisibleLayers();
var name2 = decodeURI(Name).replace(/.$/,'') +"RGB.psd";
var saveFile = File(newPath+"/"+ name2);
}
SavePSD(saveFile);
DocsWritten++;
  while (app.documents.length) {
   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  }
  */
    }
}
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true; 
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
function time(){
var date = new Date();
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;
   var digital = new Date();
   var hours = digital.getHours();
   var minutes = digital.getMinutes();
   var seconds = digital.getSeconds();
   var amOrPm = "AM";
   if (hours > 11) amOrPm = "PM";
   if (hours > 12) hours = hours - 12;
   if (hours == 0) hours = 12;
   if (minutes <= 9) minutes = "0" + minutes;
   if (seconds <= 9) seconds = "0" + seconds;
   todaysDate = "-" + hours + "_" + minutes + "_" + seconds + amOrPm;
   return todaysDate.toString();
};
sonyapaz

Stacking Groups of 3

Post by sonyapaz »

That opens them in the wrong order. I have been using that renaming script so the files are named A, B, C with A=green, B=red, C=blue.

And i need them to be A>B>C top to bottom.

However, to check I renamed the files, swaping the blue and green order, and the script works well, good coloring. Can you get it to do the layering using the blue (C) file as the base?
Paul MR

Stacking Groups of 3

Post by Paul MR »

Please try this now..
Code: Select all#target photoshop
main();
function main(){
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,500,280],"+
"panel0:Panel{bounds:[10,10,390,170] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"title:StaticText{bounds:[80,10,290,40] , text:'Stack Files' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,50,370,120] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"folder:EditText{bounds:[10,10,300,30] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"browse:Button{bounds:[310,10,351,31] , text:'<<' },"+
"fileCount:DropDownList{bounds:[240,40,346,60]},"+
"statictext1:StaticText{bounds:[10,40,230,60] , text:'Number of files to stack...' ,properties:{scrolling:undefined,multiline:undefined}}},"+
"process:Button{bounds:[10,130,180,151] , text:'Process' },"+
"button2:Button{bounds:[200,130,370,151] , text:'Cancel' }}};"
var win = new Window(dlg,'Stack Files');
win.panel0.panel1.folder.enabled=false;
win.panel0.title.graphics.font = ScriptUI.newFont("Arial","BOLDITALIC",26);
for(var a = 2;a<21;a++){
    win.panel0.panel1.fileCount.add('item',a);
    }
win.panel0.panel1.fileCount.selection=1;
win.panel0.panel1.browse.onClick = function(){
inputFolder = Folder.selectDialog("Please select the folder with Files to process");   
   if(inputFolder !=null){
      win.panel0.panel1.folder.text =  decodeURI(inputFolder.fsName);
      }
}
win.panel0.process.onClick = function(){
    if(win.panel0.panel1.folder.text ==''){
            alert("No input folder has been selected!");
            return;
        }
    win.close(1);
    process();
    }
win.center();
win.show();
function process(){
   try{
DocsWritten=0;
DupDocs=0;
NoOfFilesToStack = win.panel0.panel1.fileCount.selection.index+2;
var newPath = Folder(decodeURI(inputFolder +"/Stacked"));
if(!newPath.exists) newPath.create();
var fileList = inputFolder.getFiles(/\.(jpg)$/i);
}catch(e){alert(e.line)}
if(fileList.length % NoOfFilesToStack) {
    alert("There are not multiples of " +NoOfFilesToStack+ "\n"+fileList.length+ " files exist");
    return;
    }
while(fileList.length){
    for(var a =0; a<NoOfFilesToStack;a++){
     try{
    app.open(fileList.pop());
    }catch(e){}
        }
    saveAll();
    }
alert("New Files Written = " + DocsWritten +"\nFiles That existed = "+ DupDocs);
function saveAll(){
try{
var Name = app.documents[0].name.replace(/\.[^\.]+$/, '');
for(var a = 1;a<documents.length;a++){
activeDocument=documents[a];
activeDocument.activeLayer.duplicate(documents[0]);
activeDocument = documents[0];
activeDocument.activeLayer.name=documents[a].name.replace(/\.[^\.]+$/, '');
}

}catch(e){}
var saveFile = File(newPath+"/"+Name+"-stack.psd");
var testFile  = File(newPath+"/"+Name+"-stack.psd");
if(testFile.exists){
     testFile.rename(testFile.name.slice(0,-4) + time() + ".psd");
     DupDocs++;
     }
if(NoOfFilesToStack == 3){
activeDocument.activeLayer=activeDocument.artLayers[1];
activeDocument.artLayers[0].opacity=50;
activeDocument.artLayers[1].opacity=40;
activeDocument.activeLayer=activeDocument.artLayers[0];
activeDocument.activeLayer.autoLevels();
activeDocument.activeLayer=activeDocument.artLayers[1];
activeDocument.activeLayer.autoLevels();
activeDocument.activeLayer=activeDocument.artLayers[2];
activeDocument.activeLayer.autoLevels();
activeDocument.mergeVisibleLayers();
var name2 = decodeURI(Name).replace(/.$/,'') +"RGB.psd";
var saveFile = File(newPath+"/"+ name2);
}
SavePSD(saveFile);
DocsWritten++;

  while (app.documents.length) {
   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  }
    }
}
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true; 
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
function time(){
var date = new Date();
   var d  = date.getDate();
   var day = (d < 10) ? '0' + d : d;
   var m = date.getMonth() + 1;
   var month = (m < 10) ? '0' + m : m;
   var yy = date.getYear();
   var year = (yy < 1000) ? yy + 1900 : yy;
   var digital = new Date();
   var hours = digital.getHours();
   var minutes = digital.getMinutes();
   var seconds = digital.getSeconds();
   var amOrPm = "AM";
   if (hours > 11) amOrPm = "PM";
   if (hours > 12) hours = hours - 12;
   if (hours == 0) hours = 12;
   if (minutes <= 9) minutes = "0" + minutes;
   if (seconds <= 9) seconds = "0" + seconds;
   todaysDate = "-" + hours + "_" + minutes + "_" + seconds + amOrPm;
   return todaysDate.toString();
};
sonyapaz

Stacking Groups of 3

Post by sonyapaz »

Perfect. Thank you once again.
sonyapaz

Stacking Groups of 3

Post by sonyapaz »

So I'm a complete pain in the ass.

I recently upgraded some software on my work computer, including photoshop (now CS5 instead of CS3). Is there anyway someone can adjust the above script for me so it works the same in CS5?

Sonya