• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to I batch automate combining files as layers

New Here ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

I have 10k odd files that have a pair (so 20k total) image which is imageName.bmp and imageName_a.bmp that I would like to combine into one .psd, then perform some Photoshop Actions on, then save both layers independently to two files (one with the _a one without). Also some files don't have a _a counterpart.

What's the best way to automate this? I'm happy to learn about scripting and I already understand PS Actions. Cheers 🙂

TOPICS
Actions and scripting , Windows

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Yes, this is possible via scripting, there are numerous examples for batch processing file pairs in the forums.

 

 I have to ask why???

 

 If you are going to save out each layer as a separate layer, why bother combining them as pairs?

 

What are you doing with the action on the two layer stack, before saving out separate files again? 

 

P.S. Do you also wish to save the layered PSD as well as the separate layers?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Yeah "why" is a fair question. Basically I need to up the brightness and contrast on the first image, according to a selection based off the second. The _a image is an alpha channel pair for the main image, I don't want to affect certain parts of the image with the brightness and contrast changes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

That makes sense.

 

I am testing on a Mac, Mac and Windows can sort batch file input differently.

 

Can you please provide 3 sets of real filenames, so 6 in total.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Sure, thanks for lending a hand:

 

1: 0x7ab50e44-0x1abe787d-0x5700a70e.bmp

1_a: 0x7ab50e44-0x1abe787d-0x5700a70e_a.bmp

2: 0x7ab50e44-0x1abe787d-0x5701a5ce.bmp

2_a: 0x7ab50e44-0x1abe787d-0x5701a5ce_a.bmp

3: 0x7ab50e44-0x1abe787d-0x5701a7ce.bmp

3_a: 0x7ab50e44-0x1abe787d-0x5701a7ce_a.bmp

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

Thank you, that helps.

 

So, I presume that all files are in a single folder, or are they in a separate folder?

 

Once the 2 files are open, then what? 

Is there a specific order that the files should be in?

 

What steps will the script perform?

 

What steps will the action perform?

 

Can you map out a linear, step by step process of the automation?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

Sure, so the files are in one parent folder, and therein some subfolders (some 2 or 3 levels in). Flattening them to a single level is possible but somewhat frustrating since afterwards I'll have to put them back as they were. If it makes it easier however it can be done.

 

The script needs to open both files, and combine them into one photoshop project as seperate layers, then the action will make a selection using Colour range (the _a files only have 2 colours, black and white), then apply a brightness +30, and contrast +90 to that selection only, then save both layers as the original files (as .bmp or .png). The photoshop project itself does not need to be saved.

 

Thanks again Stephen, you are a legend!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

Should the alpha be the top layer with the image the lower?

 

If you are applying the alpha to the image and only adjusting the image, why re-save the alpha?

 

if you manually open the two files and manually combine them, does the action work as intended? 


In order to automate I need to understand the process and I am a little lost.

 

If the action is doing most of the work, that is great, I just need to understand the layer stack order and that is that... However, actions are not always good for file naming saves. I must be missing something...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

It doesn't matter what order the layers are in since you can hide layers but if I had to pick, I'd say the alpha should be on the bottom.

 

You are right in saying the alpha doesn't need to be resaved - I don't know why I thought they did, so just the main image needs to be saved. 

 

The biggest thing to get right is that the name of the image is intrinsically linked to the iamge content so if they get out of a alignment its a real pain. 

 

The only reason I need the alpha at all (otherwise this would be trivial) is to perform the selection on that layer, then apply the brightness and contrast to the other layer according to the aforementioned selection.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

So why do you have two files in the first place?  Do you need more than 53 Alpha channels which is Photoshop Alpha channel limit?  Work with layered documents you can always save flat image files like Jpeg and BMP files from your work documents which are easy to edit.   Working on Flat files is a PITA. Photoshop power come from layers, channels,  paths etc.  You should take advantages of Photoshop features.  Flat files merge all into a single layer which make working on objects like text, shape, and image hard or impossible. If you want to modify images save you work in layered files do not discard you work by only saving flat file.

 

I may have a Photo Collage template PSD file that may only have a single background layer. Still the PSD can have 53 Alpha channels that can automatically be populated with 53 images by a Photoshop script I wrote. Here is one that has three layers. The required background layer, an optionals mat ovelay layer and an adjustment layer clipped to that mat layer to colorize the mat.

image.png

 

When populated you can save out a flat 16"x20" 300dpi  jpeg file.

image.png

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

OK, this is far from perfect, however, it is the best that I can currently do (I still consider myself a beginner).

 

You should temporarily move the files that don't have a matching _a.bmp alpha file to a temporary folder so that they are not processed.

 

Hope this helps.

 

WARNINGS & NOTES FOR USE:

 

  •  Use at your own risk!!!
  •  There must be multiple pairs of files, not an odd number of input files, there is no error checking
  •  Work on copies of the original files until you are happy with the results
  •  The original .bmp file will be overwritten, I did I mention to use at your own risk and to work on copies!
  •  The code could be adjusted to save the adjusted file with a new name rather than overwrite the original (there are 10,000+ files to consider)
  •  The alpha _a.bmp files will be closed without saving changes
  •  Only the top-level folder will be processed, sub-directories must be processed separately
  •  A selection will be loaded from the RGB composite channel of the alpha data
  •  An action will then be run to complete the processing using the selection
  •  Change the action name from Molten Lead to your name
  •  Change the action set name from Default Actions to your name

 

 

// Use at your own risk!!!
// There must be multiple pairs of files, not an odd number of input files, there is no error checking
// Work on copies of the original files until you are happy with the results
// The original .bmp file will be overwritten
// The alpha _a.bmp files will be closed without saving changes
// Only the top-level folder will be processed, sub-directories must be processed separately
// A selection will be loaded from the RGB composite channel of the alpha data
// An action will then be run to complete the processing using the selection
// Change the action name from Molten Lead to your name
// Change the action set name from Default Actions to your name

#target photoshop

// Capture and suppress dialogs during batch
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;

main();

function main() {

    inputFolder = Folder.selectDialog("Please select the input folder");
    if (inputFolder == null) return;
    // Limit the file input
    var fileList = inputFolder.getFiles(/\.(bmp)$/i);
    // Force alpha-numeric list sort
    fileList.sort();

    while (fileList.length) {
        // Digit 2 for two files
        for (var a = 0; a < 2; a++) {
            try {
                app.open(fileList.pop());
            } catch (e) { }
        }

        //var fileCount = app.documents.length;
        //alert("There are " + fileCount + " files to process");

        doStuff();
    }

    function doStuff() {
        try {
            // Select the alpha document
            app.activeDocument = app.documents[0];
            // Select all
            app.activeDocument.selection.selectAll();
            // Copy selection
            app.activeDocument.selection.copy();
            // Close active document without saving
            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
            // Paste from clipboard
            app.activeDocument.paste();
            // Load RGB channel as selection
            var idsetd = charIDToTypeID("setd");
            var desc146 = new ActionDescriptor();
            var idnull = charIDToTypeID("null");
            var ref59 = new ActionReference();
            var idChnl = charIDToTypeID("Chnl");
            var idfsel = charIDToTypeID("fsel");
            ref59.putProperty(idChnl, idfsel);
            desc146.putReference(idnull, ref59);
            var idT = charIDToTypeID("T   ");
            var ref60 = new ActionReference();
            var idChnl = charIDToTypeID("Chnl");
            var idChnl = charIDToTypeID("Chnl");
            var idRGB = charIDToTypeID("RGB ");
            ref60.putEnumerated(idChnl, idChnl, idRGB);
            desc146.putReference(idT, ref60);
            executeAction(idsetd, desc146, DialogModes.NO);
            // Remove active layer
            app.activeDocument.activeLayer.remove();

            // Now do something with the selection active to limit the effects...

            /*
            // Brightness +30, Contrast +90, Use Legacy = False
            var idBrgC = charIDToTypeID( "BrgC" );
            var desc71 = new ActionDescriptor();
            var idBrgh = charIDToTypeID( "Brgh" );
            desc71.putInteger( idBrgh, 30 );
            var idCntr = charIDToTypeID( "Cntr" );
            desc71.putInteger( idCntr, 90 );
            var iduseLegacy = stringIDToTypeID( "useLegacy" );
            desc71.putBoolean( iduseLegacy, false );
            executeAction( idBrgC, desc71, DialogModes.NO );
            */

            ///////////// Your action here /////////////
            // Action to run
            var actionName = "Molten Lead";
            // Action set to run
            var actionSet = "Default Actions";
            app.doAction(actionName, actionSet);
            ///////////// Your action here /////////////

            app.activeDocument.flatten();
            app.activeDocument.close(SaveOptions.SAVECHANGES);

        } catch (e) { }
    }
}

// Restore original dialog settings
app.displayDialogs = savedDisplayDialogs;

 

 

 

23rd JUNE 2020

Initial code posted

 

24th JUNE 2020

I have added code for the Brightness/Contrast step to remove the dependency on the action, however, I have commented out the code and left the action in there for now, just in case the action is doing more than this single step...

 

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

LATEST

So, how did you go?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines