Combine two psd into one. Keep filename.
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
};
