Skip to main content
Participating Frequently
October 28, 2009
Answered

Batch combine 2 images with watermarks on opposite sides to eliminate the watermarks & save in a new folder- How?

  • October 28, 2009
  • 1 reply
  • 2445 views

I have 2 folders of images.

1 folder has images with a watermark on the lower left side of the image & the other folder has images with a watermark on the lower right side.

The images are named the same in each folder.

I've never done scripting before & I don't want to edit, flatten & save 2000 images by hand.

There has to be an efficient way of doing this.

Any help is much appreciated.

Thanks!

This topic has been closed for replies.
Correct answer Paul Riggott

This is closer.

Can you come down about a 1/3 more?

I've attached the 2 marked files and then the result.

Thank you in advance! This will save me alot of time and frustration.


I have brought the top down a little, it's now 4/5th removed from the top.

var top = activeDocument.height-((activeDocument.height/5)*4);

The whole script again..

#target photoshop
function main(){
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,650,290],"+
"panel0:Panel{bounds:[10,10,540,180] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext0:StaticText{bounds:[190,10,360,27] , text:'Merge Files' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,30,520,130] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext1:StaticText{bounds:[10,10,70,30] , text:'Folder A' ,properties:{scrolling:undefined,multiline:undefined}},"+
"foldera:EditText{bounds:[80,10,430,30] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse1:Button{bounds:[440,10,501,31] , text:'<<' },"+
"statictext2:StaticText{bounds:[10,40,70,57] , text:'Folder B' ,properties:{scrolling:undefined,multiline:undefined}},"+
"folderb:EditText{bounds:[80,40,430,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse2:Button{bounds:[440,40,500,61] , text:'<<' },"+
"statictext3:StaticText{bounds:[10,70,70,87] , text:'Output' ,properties:{scrolling:undefined,multiline:undefined}},"+
"folderc:EditText{bounds:[80,70,430,90] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse3:Button{bounds:[440,70,501,91] , text:'>>' }},"+
"Process:Button{bounds:[10,140,260,161] , text:'Process' },"+
"button4:Button{bounds:[270,140,520,161] , text:'Cancel' }}};"
var win = new Window(dlg,'Merge Files');
win.center();
win.panel0.panel1.foldera.enabled=false;
win.panel0.panel1.folderb.enabled=false;
win.panel0.panel1.folderc.enabled=false;

win.panel0.panel1.Browse1.onClick = function() {
inputFolder1 = Folder.selectDialog("Please select the folder with Files A to process");
if(inputFolder1 !=null){
  win.panel0.panel1.foldera.text =  decodeURI(inputFolder1.fsName);
  }
}
win.panel0.panel1.Browse2.onClick = function() {
inputFolder2 = Folder.selectDialog("Please select the folder with Files B to process");
if(inputFolder2 !=null){
  win.panel0.panel1.folderb.text =  decodeURI(inputFolder2.fsName);
  }
}
win.panel0.panel1.Browse3.onClick = function() {
outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder !=null){
  win.panel0.panel1.folderc.text =  decodeURI(outputFolder.fsName);
  }
}
win.panel0.Process.onClick = function(){
if(win.panel0.panel1.foldera.text == ''){
  alert("Folder A has not been selected!");
  return;
  }
if(win.panel0.panel1.folderb.text == ''){
  alert("Folder B has not been selected!");
  return;
  }
if(win.panel0.panel1.folderc.text == ''){
  alert("Output folder has not been selected!");
  return;
  }
win.close(1);
processDocuments();
}
win.show();
function processDocuments(){
var fileListA = inputFolder1.getFiles(/\.(jpg|tif|psd|png)$/i);
for (var a in fileListA){
var file = fileListA;
var fileb = File(inputFolder2+"/"+file.name);
if(!fileb.exists) continue;
var saveFile = File(outputFolder+"/"+file.name.replace(/\.[^\.]+$/, '') +".jpg");
open(file);
placeFile(fileb);
rasterLayer();
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var left = 0;
var top = activeDocument.height-((activeDocument.height/5)*4);
var right = activeDocument.width/3;
var bottom = activeDocument.height;
activeDocument.selection.select( [[left,top],[right,top],[right,bottom ],[left,bottom]]);
activeDocument.selection.invert();
activeDocument.selection.clear();
SaveJPEG(saveFile, 8);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
}
}
}
main();
function placeFile(placeFile) {
    var desc21 = new ActionDescriptor();
    desc21.putPath( charIDToTypeID('null'), new File(placeFile) );
    desc21.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
        var desc22 = new ActionDescriptor();
        desc22.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
        desc22.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
    desc21.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc22 );
    executeAction( charIDToTypeID('Plc '), desc21, DialogModes.NO );
};
function rasterLayer() {
    var desc9 = new ActionDescriptor();
        var ref4 = new ActionReference();
        ref4.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc9.putReference( charIDToTypeID('null'), ref4 );
    executeAction( stringIDToTypeID('rasterizeLayer'), desc9, 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);
};

Paul Riggott
Inspiring
October 28, 2009

This should be close.....

#target photoshop
function main(){
var dlg=
"dialog{text:'Script Interface',bounds:[100,100,650,290],"+
"panel0:Panel{bounds:[10,10,540,180] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext0:StaticText{bounds:[190,10,360,27] , text:'Merge Files' ,properties:{scrolling:undefined,multiline:undefined}},"+
"panel1:Panel{bounds:[10,30,520,130] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+
"statictext1:StaticText{bounds:[10,10,70,30] , text:'Folder A' ,properties:{scrolling:undefined,multiline:undefined}},"+
"foldera:EditText{bounds:[80,10,430,30] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse1:Button{bounds:[440,10,501,31] , text:'<<' },"+
"statictext2:StaticText{bounds:[10,40,70,57] , text:'Folder B' ,properties:{scrolling:undefined,multiline:undefined}},"+
"folderb:EditText{bounds:[80,40,430,60] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse2:Button{bounds:[440,40,500,61] , text:'<<' },"+
"statictext3:StaticText{bounds:[10,70,70,87] , text:'Output' ,properties:{scrolling:undefined,multiline:undefined}},"+
"folderc:EditText{bounds:[80,70,430,90] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},"+
"Browse3:Button{bounds:[440,70,501,91] , text:'>>' }},"+
"Process:Button{bounds:[10,140,260,161] , text:'Process' },"+
"button4:Button{bounds:[270,140,520,161] , text:'Cancel' }}};"
var win = new Window(dlg,'Merge Files');
win.center();
win.panel0.panel1.foldera.enabled=false;
win.panel0.panel1.folderb.enabled=false;
win.panel0.panel1.folderc.enabled=false;

win.panel0.panel1.Browse1.onClick = function() {
inputFolder1 = Folder.selectDialog("Please select the folder with Files A to process");
if(inputFolder1 !=null){
  win.panel0.panel1.foldera.text =  decodeURI(inputFolder1.fsName);
  }
}
win.panel0.panel1.Browse2.onClick = function() {
inputFolder2 = Folder.selectDialog("Please select the folder with Files B to process");
if(inputFolder2 !=null){
  win.panel0.panel1.folderb.text =  decodeURI(inputFolder2.fsName);
  }
}
win.panel0.panel1.Browse3.onClick = function() {
outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder !=null){
  win.panel0.panel1.folderc.text =  decodeURI(outputFolder.fsName);
  }
}
win.panel0.Process.onClick = function(){
if(win.panel0.panel1.foldera.text == ''){
  alert("Folder A has not been selected!");
  return;
  }
if(win.panel0.panel1.folderb.text == ''){
  alert("Folder B has not been selected!");
  return;
  }
if(win.panel0.panel1.folderc.text == ''){
  alert("Output folder has not been selected!");
  return;
  }
win.close(1);
processDocuments();
}
win.show();
function processDocuments(){
var fileListA = inputFolder1.getFiles(/\.(jpg|tif|psd|png)$/i);
for (var a in fileListA){
var file = fileListA;
var fileb = File(inputFolder2+"/"+file.name);
if(!fileb.exists) continue;
var saveFile = File(outputFolder+"/"+file.name.replace(/\.[^\.]+$/, '') +".jpg");
open(file);
placeFile(fileb);
rasterLayer();
SaveJPEG(saveFile, 8);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
main();
function placeFile(placeFile) {
    var desc21 = new ActionDescriptor();
    desc21.putPath( charIDToTypeID('null'), new File(placeFile) );
    desc21.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
        var desc22 = new ActionDescriptor();
        desc22.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
        desc22.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
    desc21.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc22 );
    executeAction( charIDToTypeID('Plc '), desc21, DialogModes.NO );
};
function rasterLayer() {
    var desc9 = new ActionDescriptor();
        var ref4 = new ActionReference();
        ref4.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc9.putReference( charIDToTypeID('null'), ref4 );
    executeAction( stringIDToTypeID('rasterizeLayer'), desc9, 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);
};

hifimonoAuthor
Participating Frequently
October 29, 2009

All this did was essentially copy 1 folder's images to a new folder.

I need the lower left portion of images A to be covered up by the lower left portion of images B.

image A has the watermark on the lower left and image B has the watermark on the lower right.

Paul Riggott
Inspiring
October 29, 2009

What the script does is merge both files and save out the result as you requested. You will need to supply more detail. What format are your input files?, also example files would be a great help.