Skip to main content
Participant
March 15, 2016
Question

overlay two different images (batch)

  • March 15, 2016
  • 3 replies
  • 5405 views

is a simple way to batch process two folders of images so that say... Folder 1 Image 1 is overlaid on Folder 2 Image 1 to create a composite? I have a series of images I want to overlay on to each other but I am not sure if it's possible other than by opening each by hand which would take ages.

This topic has been closed for replies.

3 replies

Participant
March 15, 2016

Thank you. I have never done any scripting before, is there somewhere I can get more detailed information on the process and this particular script? Thank you so much.

Chuck Uebele
Community Expert
Community Expert
March 15, 2016

The other question would be: Do you want to stop at each image to do something, or just combining the photos, saving them, then going back later and do some editing? Stopping to do something is more complicated.

Chuck Uebele
Community Expert
Community Expert
March 16, 2016

I don't think I need to stop at each images as I only want to blend the two images together. So Image 1 from Folder 1 is blended as layer on to Image 1 folder 2. I hope that makes sense.


Ok, the below script will combine files from two different folders then save the result to a third folder. You need to edit the script to point to folders that you have on your HD (lines 2-4). Thre is no error checking, so if you don't have the same number of files in each folder, it will stop and give you an error. If you have any other type of file other than an image file in the folder it will stop and give an error - this included XMP files, so if you're using raw files, change them to dngs first. Right now the script is set to set the top layer to overlay mode. You can change that in line 14.

#target photoshop

var folder1 = new Folder('/c/folder1/');

var folder2 = new Folder('/c/folder2/');

var saveFolder = new Folder('/c/folder3/');

var searchMask = '*.???';

var list1= folder1.getFiles(searchMask);

var list2= folder2.getFiles(searchMask);

var psdOptions = new PhotoshopSaveOptions();

psdOptions.layers = true;

for(var i=0;i<list1.length;i++){

    var doc = open(list1);

    var docName = doc.name;

    placeFile (list2, 100);

    doc.activeLayer.blendMode = BlendMode.OVERLAY;//change overlay mode

    doc.saveAs (new File(saveFolder +'/' + docName.split('.')[0] + '.psd'), psdOptions);

    doc.close(SaveOptions.DONOTSAVECHANGES);

    };

function placeFile(file,scale){

    try{

        var idPlc = charIDToTypeID( "Plc " );

            var desc2 = new ActionDescriptor();

            var idnull = charIDToTypeID( "null" );

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

            var idFTcs = charIDToTypeID( "FTcs" );

            var idQCSt = charIDToTypeID( "QCSt" );

            var idQcsa = charIDToTypeID( "Qcsa" );

            desc2.putEnumerated( idFTcs, idQCSt, idQcsa );

            var idOfst = charIDToTypeID( "Ofst" );

                var desc3 = new ActionDescriptor();

                var idHrzn = charIDToTypeID( "Hrzn" );

                var idPxl = charIDToTypeID( "#Pxl" );

                desc3.putUnitDouble( idHrzn, idPxl, 0.000000 );

                var idVrtc = charIDToTypeID( "Vrtc" );

                var idPxl = charIDToTypeID( "#Pxl" );

                desc3.putUnitDouble( idVrtc, idPxl, 0.000000 );

            var idOfst = charIDToTypeID( "Ofst" );

            desc2.putObject( idOfst, idOfst, desc3 );

            var idWdth = charIDToTypeID( "Wdth" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc2.putUnitDouble( idWdth, idPrc, scale );

            var idHght = charIDToTypeID( "Hght" );

            var idPrc = charIDToTypeID( "#Prc" );

            desc2.putUnitDouble( idHght, idPrc, scale );

            var idAntA = charIDToTypeID( "AntA" );

            desc2.putBoolean( idAntA, true );

        executeAction( idPlc, desc2, DialogModes.NO );

       

        }

    catch(e){}

    }//end function placeFile

Chuck Uebele
Community Expert
Community Expert
March 15, 2016

How do you want to composite them: two separate image in one image, or overlapping with some sort of blend mode or masking?

Participant
March 15, 2016

I want to overlay one image on top of the other and blend with multiply or similar.

Chuck Uebele
Community Expert
Community Expert
March 15, 2016

You can do that pretty easily with scripting. Just a matter of defining the two folder, and making sure they are in the order you want. You can then use scriptlistener to get the code for placing a file into another. Then you put all the files from the folder in a new array with the getFiles() statement. then you create a loop to go through that array and open one of the files from one folder, then place a file from the other folder. You can then change the blend mode of the layer to whatever you want, and save and close, or what ever you want to do with the file.

c.pfaffenbichler
Community Expert
Community Expert
March 15, 2016

You may want to ask over on the Scripting Forum, the task has come up repeatedly and can usually be automated but your description seems insufficient so far:

Photoshop Scripting