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

Batch processing multiple images into one layered file

New Here ,
Nov 10, 2020 Nov 10, 2020

Hopefully someone can help. I need to create some type of script or action to do the following...

 

I have 8000+ images in one folder named as follows:

image1a.psd
image1b.psd
image2a.psd
image2b.psd

etc.

all the way to image 4000a.psd & image4000b.psd

 

I need to combine "image1a.psd" and "image1b.psd" as layers into a single .psd file for all 8000+ images.

 

How can I accomplish this?

 

Thanks!

 

 

516
Translate
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

correct answers 1 Correct answer

Community Expert , Nov 10, 2020 Nov 10, 2020

I just realized that in the lastest version of PS, you can ungroup smart objects. So I changed the code to that it won't flatten the "b" image.

#target photoshop
var srcFolder = new Folder('~/desktop/combine-test/');
var mask = '*a.psd'
var fileList = srcFolder.getFiles (mask);
var psdOptions = new PhotoshopSaveOptions()
psdOptions.layers = true

for(var i=0;i<fileList.length;i++){
    var sndFileName = fileList[i].name.substring (0, fileList[i].name.length-5)
    var sndFile = new File(srcFolde
...
Translate
Adobe
Community Expert ,
Nov 10, 2020 Nov 10, 2020

There have been some other requests like this. You might want to do a search and see if you can fine something that works for you.

Translate
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 ,
Nov 10, 2020 Nov 10, 2020

Thank you, I have looked at other posts with similar questions, but have not yet been able to find a solution for my specific need...

 

Translate
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 ,
Nov 10, 2020 Nov 10, 2020

So what are your specific needs? The easiest, would be to combine all the files and save them as a new file, then you can go back and do whatever editing you need to do.

Translate
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 ,
Nov 10, 2020 Nov 10, 2020

Yes, I understand but to do that manually would take too long. For example, it takes me 30 seconds to open the files and combine layers, then save as a new file... working non-stop 8 hours / day it would take me 3 1/2 weeks to complete. Obviously I need an automated solution 😞

Translate
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 ,
Nov 10, 2020 Nov 10, 2020

No, what I mean is if you combine the two files, what do you want to do with them? Of do you just want to combine the files and save?

Translate
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 ,
Nov 10, 2020 Nov 10, 2020

Ah, I see... so I am combining the 2 layers together to run another script that creates an a\image as shown in the attachment. Basically taking 2 individual sides of a business card to create a realistic looking business card mockup for a shopping cart.

example.jpgexpand image

Translate
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 ,
Nov 10, 2020 Nov 10, 2020

also do these files have multiple layers? if so do you flatten them or put them in a smart object?

Translate
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 ,
Nov 10, 2020 Nov 10, 2020

Well, you can try this script. It will combine two file if the naming is how you state with the files ending in a and b. It will flatten the b file. You can comment out the rasterizing function (ras()) to leave it as a smart object. It will save the file as "c" in the same folder. You will need to change the folder name.

 

#target photoshop
var srcFolder = new Folder('~/desktop/combine-test/');
var mask = '*a.psd'
var fileList = srcFolder.getFiles (mask);
var psdOptions = new PhotoshopSaveOptions()
psdOptions.layers = true

for(var i=0;i<fileList.length;i++){
    var sndFileName = fileList[i].name.substring (0, fileList[i].name.length-5)
    var sndFile = new File(srcFolder + '/' + sndFileName + 'b.psd')
    var doc = open(fileList[i]);
    placeFile (sndFile);
    ras ();
    doc.saveAs (new File(srcFolder +'/' + sndFileName + 'c.psd'), psdOptions)
    doc.close (SaveOptions.DONOTSAVECHANGES);
    }

    

function placeFile(file){
    var idPlc = charIDToTypeID( "Plc " );
        var desc12 = new ActionDescriptor();
        var idIdnt = charIDToTypeID( "Idnt" );
        desc12.putInteger( idIdnt, 2 );
        var idnull = charIDToTypeID( "null" );
        desc12.putPath( idnull, new File( file ) );
        var idFTcs = charIDToTypeID( "FTcs" );
        var idQCSt = charIDToTypeID( "QCSt" );
        var idQcsa = charIDToTypeID( "Qcsa" );
        desc12.putEnumerated( idFTcs, idQCSt, idQcsa );
        var idOfst = charIDToTypeID( "Ofst" );
            var desc13 = new ActionDescriptor();
            var idHrzn = charIDToTypeID( "Hrzn" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc13.putUnitDouble( idHrzn, idPxl, 0.000000 );
            var idVrtc = charIDToTypeID( "Vrtc" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc13.putUnitDouble( idVrtc, idPxl, 0.000000 );
        var idOfst = charIDToTypeID( "Ofst" );
        desc12.putObject( idOfst, idOfst, desc13 );
    executeAction( idPlc, desc12, DialogModes.NO );   
    }

function ras(){
       var idrasterizeLayer = stringIDToTypeID( "rasterizeLayer" );
        var desc16 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref1.putEnumerated( idLyr, idOrdn, idTrgt );
        desc16.putReference( idnull, ref1 );
    executeAction( idrasterizeLayer, desc16, DialogModes.NO );
    } 
Translate
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 ,
Nov 10, 2020 Nov 10, 2020

Thank you, I will give it a try. 

Translate
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 ,
Nov 10, 2020 Nov 10, 2020
LATEST

I just realized that in the lastest version of PS, you can ungroup smart objects. So I changed the code to that it won't flatten the "b" image.

#target photoshop
var srcFolder = new Folder('~/desktop/combine-test/');
var mask = '*a.psd'
var fileList = srcFolder.getFiles (mask);
var psdOptions = new PhotoshopSaveOptions()
psdOptions.layers = true

for(var i=0;i<fileList.length;i++){
    var sndFileName = fileList[i].name.substring (0, fileList[i].name.length-5)
    var sndFile = new File(srcFolder + '/' + sndFileName + 'b.psd')
    var doc = open(fileList[i]);
    placeFile (sndFile);
    undoSO ();
    doc.saveAs (new File(srcFolder +'/' + sndFileName + 'c.psd'), psdOptions)
    doc.close (SaveOptions.DONOTSAVECHANGES);
    }

function undoSO(){
    var idplacedLayerConvertToLayers = stringIDToTypeID( "placedLayerConvertToLayers" );
    executeAction( idplacedLayerConvertToLayers, undefined, DialogModes.NO );    
    
    var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" );
        var desc7 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref3 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref3.putEnumerated( idLyr, idOrdn, idTrgt );
        desc7.putReference( idnull, ref3 );
    executeAction( idungroupLayersEvent, desc7, DialogModes.NO );    
    }

function placeFile(file){
    var idPlc = charIDToTypeID( "Plc " );
        var desc12 = new ActionDescriptor();
        var idIdnt = charIDToTypeID( "Idnt" );
        desc12.putInteger( idIdnt, 2 );
        var idnull = charIDToTypeID( "null" );
        desc12.putPath( idnull, new File( file ) );
        var idFTcs = charIDToTypeID( "FTcs" );
        var idQCSt = charIDToTypeID( "QCSt" );
        var idQcsa = charIDToTypeID( "Qcsa" );
        desc12.putEnumerated( idFTcs, idQCSt, idQcsa );
        var idOfst = charIDToTypeID( "Ofst" );
            var desc13 = new ActionDescriptor();
            var idHrzn = charIDToTypeID( "Hrzn" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc13.putUnitDouble( idHrzn, idPxl, 0.000000 );
            var idVrtc = charIDToTypeID( "Vrtc" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc13.putUnitDouble( idVrtc, idPxl, 0.000000 );
        var idOfst = charIDToTypeID( "Ofst" );
        desc12.putObject( idOfst, idOfst, desc13 );
    executeAction( idPlc, desc12, DialogModes.NO );   
    }
Translate
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