Skip to main content
Participant
October 18, 2020
Answered

Open photos with same filename as layers

  • October 18, 2020
  • 4 replies
  • 3995 views

Hi.

I'm looking for a method to batch combine two photos with for example the same filename to layers in one tif file.

Example:

DSC0001.tif = Layer 1

DSC0001.jpg = Layer 2

I do process photos twice in different ways and now I manually open photo by photo, import different version and do 50% opacity :(

Please help 🙂

 

Sorry for my bad English.

This topic has been closed for replies.
Correct answer Stephen Marsh

I made a quick edit to a script that I had previously hacked together. A single source folder is selected and the script will then process pairs of files, stacking one over the other at 50% opacity, then save out a JPEG into a newly named folder within the source folder. 

 

It is assumed that all file pairs have correct alphabetical pair names for sorting and that the total count of all files is divisible by 2.

 

 

#target photoshop

var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;

main();

function main() {
    inputFolder = Folder.selectDialog("Please select the folder with Files to process");
    if (inputFolder === null) return;
    var newPath = Folder(decodeURI(inputFolder + "/Combined")); // Create sub-dir 
    if (!newPath.exists) newPath.create();
    var fileList = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|png|psd)$/i); // Limit file format input
    fileList.sort(); // Force alpha-numeric list sort
    while (fileList.length) {
        for (var a = 0; a < 2; a++) { // Digit 2 for two files
            try {
                app.open(fileList.pop());
            } catch (e) { }
        }
        processFiles();
    }

    alert("Done!");

    function processFiles() {
        try {
            var Name = app.documents[0].name.replace(/\.[^\.]+$/, ''); // Remove file extension

            app.activeDocument = documents[1];
            app.activeDocument.activeLayer.duplicate(documents[0]);
            app.activeDocument = documents[0];

            var doc = app.activeDocument;
            doc.activeLayer.opacity = 50.0; // Layer opacity
            doc.activeLayer.blendMode = BlendMode.NORMAL; // Blend mode

            app.displayDialogs = restoreDialogMode;

        } catch (e) { }
        var saveFile = File(newPath + "/" + Name + "_Combined" + ".tif");
        saveTIFF(saveFile);
        while (app.documents.length) {
            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }
}

function saveTIFF(saveFile) {
    tiffSaveOptions = new TiffSaveOptions();
    tiffSaveOptions.embedColorProfile = true;
    tiffSaveOptions.byteOrder = ByteOrder.IBM;
    tiffSaveOptions.transparency = true;
    tiffSaveOptions.layers = true;
    tiffSaveOptions.layerCompression = LayerCompression.ZIP;
    tiffSaveOptions.interleaveChannels = true;
    tiffSaveOptions.alphaChannels = true;
    tiffSaveOptions.annotations = true;
    tiffSaveOptions.spotColors = true;
    tiffSaveOptions.saveImagePyramid = false;
    // NONE | JPEG | TIFFLZW | TIFFZIP
    tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
    app.activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}

 

 

The script can be modified to save out a TIFF if it otherwise performs as required... What TIFF save options are needed?

 

EDIT: I have updated the code with TIFF save options rather than JPEG.

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

4 replies

emilcabajAuthor
Participant
October 20, 2020

Works great 😄

Thank you all for your help 🙂

Stephen Marsh
Community Expert
Community Expert
October 27, 2020

Thanks for the feedback, please mark the answer/answers that helped you as correct so that others with the same issue know that there is a solution.

emilcabajAuthor
Participant
November 4, 2020

Great job!!!!!!!!!!!!!!

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
October 20, 2020

I made a quick edit to a script that I had previously hacked together. A single source folder is selected and the script will then process pairs of files, stacking one over the other at 50% opacity, then save out a JPEG into a newly named folder within the source folder. 

 

It is assumed that all file pairs have correct alphabetical pair names for sorting and that the total count of all files is divisible by 2.

 

 

#target photoshop

var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;

main();

function main() {
    inputFolder = Folder.selectDialog("Please select the folder with Files to process");
    if (inputFolder === null) return;
    var newPath = Folder(decodeURI(inputFolder + "/Combined")); // Create sub-dir 
    if (!newPath.exists) newPath.create();
    var fileList = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|png|psd)$/i); // Limit file format input
    fileList.sort(); // Force alpha-numeric list sort
    while (fileList.length) {
        for (var a = 0; a < 2; a++) { // Digit 2 for two files
            try {
                app.open(fileList.pop());
            } catch (e) { }
        }
        processFiles();
    }

    alert("Done!");

    function processFiles() {
        try {
            var Name = app.documents[0].name.replace(/\.[^\.]+$/, ''); // Remove file extension

            app.activeDocument = documents[1];
            app.activeDocument.activeLayer.duplicate(documents[0]);
            app.activeDocument = documents[0];

            var doc = app.activeDocument;
            doc.activeLayer.opacity = 50.0; // Layer opacity
            doc.activeLayer.blendMode = BlendMode.NORMAL; // Blend mode

            app.displayDialogs = restoreDialogMode;

        } catch (e) { }
        var saveFile = File(newPath + "/" + Name + "_Combined" + ".tif");
        saveTIFF(saveFile);
        while (app.documents.length) {
            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }
}

function saveTIFF(saveFile) {
    tiffSaveOptions = new TiffSaveOptions();
    tiffSaveOptions.embedColorProfile = true;
    tiffSaveOptions.byteOrder = ByteOrder.IBM;
    tiffSaveOptions.transparency = true;
    tiffSaveOptions.layers = true;
    tiffSaveOptions.layerCompression = LayerCompression.ZIP;
    tiffSaveOptions.interleaveChannels = true;
    tiffSaveOptions.alphaChannels = true;
    tiffSaveOptions.annotations = true;
    tiffSaveOptions.spotColors = true;
    tiffSaveOptions.saveImagePyramid = false;
    // NONE | JPEG | TIFFLZW | TIFFZIP
    tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
    app.activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}

 

 

The script can be modified to save out a TIFF if it otherwise performs as required... What TIFF save options are needed?

 

EDIT: I have updated the code with TIFF save options rather than JPEG.

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

JJMack
Community Expert
Community Expert
October 20, 2020

The script  saved flat Jpeg so they could be used on the web.  There a Save PSD option that can save layer files if  you want to be able to tweak or edit the populated template.  With your modification they need to tun a second batch job to save the Tiff Files as jpeg.  You should have changed the save PSD option to Save Tiff option.

JJMack
Stephen Marsh
Community Expert
Community Expert
October 20, 2020

JJMack's scripts are a good place to start.

 

I adapted one of his scripts for this task in another forum topic:

 

https://community.adobe.com/t5/photoshop/batch-automating-sequences-of-images/m-p/10619866

https://github.com/MarshySwamp/Layer-Stack-N-Number-of-Files-Filename-as-Top-Layer

 

JJMack
Community Expert
Community Expert
October 18, 2020

The "BatchMockupTemplates.jsx"  in my Free Photoshop Photo Collage and Mockup Toolkit  will do that but save the combines images as a jpeg and optionally as a Layered PSD. There is no option to save layered Tiff files.  All you need do is create a mockup template for how you want to combine the two images, and have the images in two folder and point the script to the templates, images collection and output destination.

JJMack
JJMack
Community Expert
Community Expert
October 20, 2020

To create the mockup template all you need to do is open a net document that has a canvas size and print resolution as your two image files.  Place in one Tif image to cover the canvas. then place in one jpeg to covet the first image. Set the layers opacity to 50%.  and save the document as your Mockup PSD template. 

 

Put the mock in a job folder sub folder Mockup.  Create a Replacement Image collection folder in the job folder and in the collection folder in a sub folder obj0 and sub folder obj1. Store you jpeg files in folder objo and store your tiff files in obj1. The run the script do not forget to check save psd file

 

You could add additional mockup templates into the mockup folder where you would mask half the top Smart object layer to let the bottom object show in the mask off half.  An additional one where the canvas is twice as wide and you place the images in side by side the script would populate all three templates in a single run 

 

JJMack