Skip to main content
mb26
Participant
April 22, 2015
Question

Automation of picture overlay/screen

  • April 22, 2015
  • 2 replies
  • 985 views

Hi! I have many pairs of pictures that need to be overlaid i.e. a1 with a2, b1 with b2 etc. I would like to import the pairs of pictures and then overlay them. Once overlaid, I would also like to reduce the brightness of the top layer.

I have over 4000 pairs of these pictures and I wish automate it. I have some basic programming experience but I'm unsure where to start. Any advice/guidance would be appreciated.

This topic has been closed for replies.

2 replies

mb26
mb26Author
Participant
June 14, 2015

Thank you for your help.

 

Over the last few weeks, I have been trying to learn coding for photoshop and though I have managed to learn a bit, I wasn’t able edit the code successfully.

 

Would anyone be able to assist me in modifying the above code so that it is able to overlay 2 or 3 images, depending whether the third file existed in the folder. That is, if the images are named:

-       001_1, 001_2, 001_3 and

-       002_1, 002_2

-       003_1, 003_2, 003_3

 

Then it would merge the first 3, and then the next 2, and then the next 3, etc. I can follow any naming convention required (some folders have 100+ files).

 

Any help is much appreciated.

Thanks

c.pfaffenbichler
Community Expert
Community Expert
June 14, 2015

I suppose this may be a lot more convoluted than the result would require but nonetheless maybe it helps.

The result is an Array of Arrays – these Arrays contain a String (the filename minus the number and suffix) and an Array of the files that "fit this name".

You could then run the "merging"-operation on the files in those Arrays.

// 2015, use it at your own risk;

// dialog for folder-selection;

var theFolder = Folder.selectDialog ("select a folder containing the images");

if (theFolder) {

var theFilesOne = theFolder.getFiles(checkFor);

// create the psd-options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = false;

psdOpts.layers = true;

psdOpts.spotColors = true;

// run through the files;

var theArray = new Array;

for (var a  = 0; a < theFilesOne.length; a++) {

var theFile = theFilesOne;

var theName = File(theFile).name.match(/(.*)\.[^\.]+$/)[1];

var theRegExp = new RegExp('[0-9]{1,7}$','i');

var theNumber = theName.match(theRegExp);

var thePrefix = theName.replace(theRegExp, "");

var inArray = false;

for (var b = 0; b < theArray.length; b++) {

if (theArray[0] == thePrefix) {

theArray[1].push(theFile)

inArray = true;

}

else {}

};

if (inArray == false || a == 0) {theArray.push([thePrefix, [theFile]])};

}

for (var c = 0; c < theArray.length; c++) (alert (theArray[1].join("\n\n")))

};

////////////////////////////////////

////// check for psd, tif or jpg //////

function checkFor (theFile) {

  if (theFile.name.slice(-4) == ".psd" || theFile.name.slice(-4) == ".tif" || theFile.name.slice(-4) == ".jpg") {return true}

  else {return false}

  };

c.pfaffenbichler
Community Expert
Community Expert
April 22, 2015

Are the images flat in themselves?

mb26
mb26Author
Participant
April 22, 2015

Yes they are all flat images saved as TIFF files and are of the same size.

c.pfaffenbichler
Community Expert
Community Expert
April 22, 2015

Not sure what you meant by

reduce the brightness of the top layer

exactly, this would reduce its opacity.

// 2015, use it at your own risk;

#target "photoshop-70.032"

// dialog for folder-selection;

var theFolder = Folder.selectDialog ("select a folder containing the images");

var theFolderTarget = Folder.selectDialog ("select a folder to save the combined images to");

if (theFolder && theFolderTarget) {

  var theFilesOne = theFolder.getFiles(checkFor);

// create the psd-options;

  psdOpts = new PhotoshopSaveOptions();

  psdOpts.embedColorProfile = true;

  psdOpts.alphaChannels = false;

  psdOpts.layers = true;

  psdOpts.spotColors = true;

// run through the files;

  for (var a  = 0; a < theFilesOne.length; a++) {

  var theFile = File(theFilesOne);

  var theName = File(theFile).name.match(/(.*)\.[^\.]+$/)[1];

// get number and add 1;

  var theNumber = theName.match(new RegExp('[0-9]{1,7}$','i'));

  if (String(theNumber/2).indexOf(".") != -1) {

  var theOtherNumber = Number(theNumber)+1;

  while (String(theOtherNumber).length < String(theNumber).length) {

  theOtherNumber = String("0"+String(theOtherNumber));

  };

  var theOtherFile = File(String(theFilesOne).replace(theNumber, theOtherNumber));

// if corresponding file exists;

  if (theOtherFile.exists == true) {

  var thisFile = app.open(theFile);

  thisFile.activeLayer = thisFile.layers[0];

// place foreground-image;

  var theSO = placeScaleRotateFile (theOtherFile, 0, 0, 100, 100, 0);

  theSO.opacity = 50;

// save the combined files;

  thisFile.saveAs(new File (theFolderTarget + "/" + theName + "_comb.psd"), psdOpts)

  thisFile.close(SaveOptions.DONOTSAVECHANGES);

  }

  }

  }

  };

////////////////////////////////////

////// check for psd, tif or jpg //////

function checkFor (theFile) {

  if (theFile.name.slice(-4) == ".psd" || theFile.name.slice(-4) == ".tif" || theFile.name.slice(-4) == ".jpg") {return true}

  else {return false}

  };

////// place //////

function placeScaleRotateFile (file, xOffset, yOffset, theXScale, theYScale, theAngle) {

// =======================================================

var idPlc = charIDToTypeID( "Plc " );

    var desc5 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc5.putPath( idnull, new File( file ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc5.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc6 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idHrzn, idPxl, xOffset );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc6.putUnitDouble( idVrtc, idPxl, yOffset );

    var idOfst = charIDToTypeID( "Ofst" );

    desc5.putObject( idOfst, idOfst, desc6 );

    var idWdth = charIDToTypeID( "Wdth" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idWdth, idPrc, theYScale );

    var idHght = charIDToTypeID( "Hght" );

    var idPrc = charIDToTypeID( "#Prc" );

    desc5.putUnitDouble( idHght, idPrc, theXScale );

    var idAngl = charIDToTypeID( "Angl" );

    var idAng = charIDToTypeID( "#Ang" );

    desc5.putUnitDouble( idAngl, idAng,theAngle );

executeAction( idPlc, desc5, DialogModes.NO );

return app.activeDocument.activeLayer;

};