Skip to main content
Known Participant
September 16, 2019
Question

Combine two psd into one. Keep filename.

  • September 16, 2019
  • 4 replies
  • 2321 views

Hey guys, I'm asking again the same question. For some reason my question dissapeared after forum update.

So the idea is to combine together two psd files but keep the filename of the first image input.

Example :  test-me-1.psd + test-me-5.psd = test-me-1.psd(final result)

I found this script here which does a pretty good job till the point of naming the end file : Line 125

 

theFile.saveAs(new File (theFolderThree + "/file" + bufferNumberWithZeros((a + 1), 4) ), psdOpts)

 

Would appreciate some help on how to tweek it so it could save it as I needed.

#target photoshop

// dialog for folder-selection;

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

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

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

if (theFolderOne && theFolderTwo && theFolderThree) {

var theFilesOne = theFolderOne.getFiles(checkFor);

var theFilesTwo = theFolderTwo.getFiles(checkFor);

// check if both folders contain the same number of files;

if (theFilesOne.length != theFilesTwo.length) {

alert ("the folders don’t contain the same number of images")

}

// else do the stuff;

else {

// 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++) {

// open background-image;

var theFile = app.open(File(theFilesOne[a]));

theFile.activeLayer = theFile.layers[0];

// place foreground-image;

var idPlc = charIDToTypeID( "Plc " );

var desc6 = new ActionDescriptor();

var idAs = charIDToTypeID( "As  " );

var desc7 = new ActionDescriptor();

var idfsel = charIDToTypeID( "fsel" );

var idpdfSelection = stringIDToTypeID( "pdfSelection" );

var idpage = stringIDToTypeID( "page" );

desc7.putEnumerated( idfsel, idpdfSelection, idpage );

var idPgNm = charIDToTypeID( "PgNm" );

desc7.putInteger( idPgNm, 1 );

var idCrop = charIDToTypeID( "Crop" );

var idcropTo = stringIDToTypeID( "cropTo" );

var idboundingBox = stringIDToTypeID( "boundingBox" );

desc7.putEnumerated( idCrop, idcropTo, idboundingBox );

var idPDFG = charIDToTypeID( "PDFG" );

desc6.putObject( idAs, idPDFG, desc7 );

var idnull = charIDToTypeID( "null" );

desc6.putPath( idnull, new File( theFilesTwo[a] ) );

var idFTcs = charIDToTypeID( "FTcs" );

var idQCSt = charIDToTypeID( "QCSt" );

var idQcsa = charIDToTypeID( "Qcsa" );

desc6.putEnumerated( idFTcs, idQCSt, idQcsa );

var idOfst = charIDToTypeID( "Ofst" );

var desc8 = new ActionDescriptor();

var idHrzn = charIDToTypeID( "Hrzn" );

var idRlt = charIDToTypeID( "#Rlt" );

desc8.putUnitDouble( idHrzn, idRlt, 0.000000 );

var idVrtc = charIDToTypeID( "Vrtc" );

var idRlt = charIDToTypeID( "#Rlt" );

desc8.putUnitDouble( idVrtc, idRlt, 0.000000 );

var idOfst = charIDToTypeID( "Ofst" );

desc6.putObject( idOfst, idOfst, desc8 );

var idAntA = charIDToTypeID( "AntA" );

desc6.putBoolean( idAntA, true );

executeAction( idPlc, desc6, DialogModes.NO );

// save the combined files;

theFile.saveAs(new File (theFolderThree + "/file" + bufferNumberWithZeros((a + 1), 4) ), psdOpts)

theFile.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}

};

////// buffer number with zeros //////

function bufferNumberWithZeros (number, places) {

var theNumberString = String(number);

for (var o = 0; o < (places - String(number).length); o++) {

theNumberString = String("0" + theNumberString)

};

return theNumberString

};

 

4 replies

Stephen Marsh
Community Expert
Community Expert
September 21, 2019

joshuab10257965 – I have modified the code to save the combined file using the first input filename.

 

It seemed to work fine for a single image, however when combining multiple images, the order was messed up and the files were not "paired" correctly (if that is the expectation). I tried to include .sort() code without success.

 

 

 

// community.adobe.com/t5/Photoshop/Combine-two-psd-into-one-Keep-filename/td-p/10610400

#target photoshop

// dialog for folder-selection;

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

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

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

if (theFolderOne && theFolderTwo && theFolderThree) {

var theFilesOne = theFolderOne.getFiles(checkFor);

var theFilesTwo = theFolderTwo.getFiles(checkFor);

// check if both folders contain the same number of files;

if (theFilesOne.length != theFilesTwo.length) {

alert ("the folders don’t contain the same number of images")

}

// else do the stuff;

else {

// 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++) {

// open background-image;

var theFile = app.open(File(theFilesOne[a]));

theFile.activeLayer = theFile.layers[0];

// ADDED BY STEPHEN A. MARSH 2019: Capture the first filename to use when saving the combined file
var theFirstName = theFile.name.replace(/\.[^\.]+$/, ''); 

// place foreground-image;

var idPlc = charIDToTypeID( "Plc " );

var desc6 = new ActionDescriptor();

var idAs = charIDToTypeID( "As  " );

var desc7 = new ActionDescriptor();

var idfsel = charIDToTypeID( "fsel" );

var idpdfSelection = stringIDToTypeID( "pdfSelection" );

var idpage = stringIDToTypeID( "page" );

desc7.putEnumerated( idfsel, idpdfSelection, idpage );

var idPgNm = charIDToTypeID( "PgNm" );

desc7.putInteger( idPgNm, 1 );

var idCrop = charIDToTypeID( "Crop" );

var idcropTo = stringIDToTypeID( "cropTo" );

var idboundingBox = stringIDToTypeID( "boundingBox" );

desc7.putEnumerated( idCrop, idcropTo, idboundingBox );

var idPDFG = charIDToTypeID( "PDFG" );

desc6.putObject( idAs, idPDFG, desc7 );

var idnull = charIDToTypeID( "null" );

desc6.putPath( idnull, new File( theFilesTwo[a] ) );

var idFTcs = charIDToTypeID( "FTcs" );

var idQCSt = charIDToTypeID( "QCSt" );

var idQcsa = charIDToTypeID( "Qcsa" );

desc6.putEnumerated( idFTcs, idQCSt, idQcsa );

var idOfst = charIDToTypeID( "Ofst" );

var desc8 = new ActionDescriptor();

var idHrzn = charIDToTypeID( "Hrzn" );

var idRlt = charIDToTypeID( "#Rlt" );

desc8.putUnitDouble( idHrzn, idRlt, 0.000000 );

var idVrtc = charIDToTypeID( "Vrtc" );

var idRlt = charIDToTypeID( "#Rlt" );

desc8.putUnitDouble( idVrtc, idRlt, 0.000000 );

var idOfst = charIDToTypeID( "Ofst" );

desc6.putObject( idOfst, idOfst, desc8 );

var idAntA = charIDToTypeID( "AntA" );

desc6.putBoolean( idAntA, true );

executeAction( idPlc, desc6, DialogModes.NO );

// save the combined files;

// theFile.saveAs(new File (theFolderThree + "/file" + bufferNumberWithZeros((a + 1), 4) ), psdOpts)

// MODIFIED BY STEPHEN A. MARSH 2019: Use the first filename
theFile.saveAs(new File (theFolderThree + "/" + theFirstName ), psdOpts) 

theFile.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}

};

////// buffer number with zeros //////

function bufferNumberWithZeros (number, places) {

var theNumberString = String(number);

for (var o = 0; o < (places - String(number).length); o++) {

theNumberString = String("0" + theNumberString)

};

return theNumberString

};

 

 

Kukurykus
Legend
September 16, 2019

The reason is all posts from between Aug, 22th - Sep, 9th weren't meant to be archived.

Known Participant
September 17, 2019
@Kukurykus can you please have a look on the code above and try to help me ? would appreciate that !
Kukurykus
Legend
September 17, 2019

 

theFile.saveAs(File(theFolderThree + '/' + theFile.name.split(/\./)[0]), psdOpts)

 

Trevor.Dennis
Community Expert
Community Expert
September 16, 2019

Ged, this is sure a temporary situation.  Least ways I hope it is.  There are just 18 forums at the moment

https://community.adobe.com/

The Overview pages had all sorts of invaluble links and information. with the Photoshop Overview pager being one of  best examples.  Where do we find that information now?  Where do we send people when they ask about tablet setup as an example?

 

The Premeire Pro forum was another example with an amazing array of useful links on its Overview page.  

 

OK, I have just discovered that if you tick all the options, the list expands dramatically.

September 16, 2019

Nice one Trevor, I was wondering where all the other forums where, now if only they would populate in alphabetical other 🙂

September 16, 2019

Moving to Photoshop Scripting

Edit: cancel that can't find the Photoshop Scripting forum

Known Participant
September 16, 2019
yeah it's combined together now under just photoshop 😞 and tagged as actions and scripting