Copy link to clipboard
Copied
Good afternoon all.
I am struggling with a a batch photomerge script. Using PS2023
I want to run a photoshop script that will search through a series of subfolders and find folders ending in _Merge and will merge all .tifs in that folder. IT should output as an uncompressed tif.
I am able to do this for the most part thanks to copying code from several different forum posts that people have previously posted. The only thing is I have unsighly white border areas along the ouside of some of the edges of the tiffs. If I use photomerge the manual way I can use the content aware fill and it works great but its not allowing me to do this via a script.
Does anyone know of a work around for this?
Also my files are ending up very big compared to if I use the manual photmerge action. Very often several times the size of the tifs I use to create the merge.?
Here is the code and hopefully it can be of use to someone else also.
Many thanks
// https://graphicdesign.stackexchange.com/questions/125106/multiple-panorama-automation-in-photoshop
// https://graphicdesign.stackexchange.com/questions/129569/batch-photomerge-only-process-images-in-folder-with-specific-title
var runphotomergeFromScript = true; // must be before Photomerge include
//@includepath "/C:\PSTEST\scripts/"
//@include "Photomerge.jsx"
//@show include
var psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
psdOpts.layers = true;
(function()
{
var workFolder = Folder.selectDialog();
if (workFolder == null) return false;
var folders = getSubfolders(workFolder, 'Merge');
if (folders.length == 0) return false
for (var i = 0; i < folders.length; i++)
{
var fList = folders[i].getFiles('*.tif');
if (fList.length == 0) continue;
// override Photomerge.jsx settings. Default is "Auto". Uncomment to override the default.
photomerge.alignmentKey = "Auto";
//photomerge.alignmentKey = "Prsp";
//photomerge.alignmentKey = "cylindrical";
//photomerge.alignmentKey = "spherical";
//photomerge.alignmentKey = "sceneCollage";
//photomerge.alignmentKey = "translation"; // "Reposition" in layout dialog
// other setting that may need to be changed. Defaults below
photomerge.advancedBlending = true; // 'Blend Images Together' checkbox in dialog
photomerge.lensCorrection = true; // Geometric Distortion Correction'checkbox in dialog
photomerge.removeVignette = true; // 'Vignette Removal' checkbox in dialog
try
{
if (fList.length > 1)
{
photomerge.createPanorama(fList, false);
}
}
catch (e)
{
alert(e + '\nLine: ' + e.line)
}
// https://stackoverflow.com/questions/45771379/how-can-i-merge-visible-to-a-layer-in-a-photoshop-script
activeDocument.mergeVisibleLayers();
activeDocument.activeLayer.autoContrast(); // Apply contrast
// saving
var saveFile = {
name: folders[i].name,
path: fList[0].parent
}
//savePSD(saveFile)
//saveJPG(saveFile)
saveTIF(saveFile)
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
})()
function saveTIF(data)
{
var desc = new ActionDescriptor();
var descOptions = new ActionDescriptor();
descOptions.putEnumerated(charIDToTypeID('BytO'), charIDToTypeID('Pltf'), charIDToTypeID('Mcnt'));
descOptions.putEnumerated(stringIDToTypeID('layerCompression'), charIDToTypeID('Encd'), stringIDToTypeID('RLE'));
desc.putObject(charIDToTypeID('As '), charIDToTypeID('TIFF'), descOptions);
desc.putPath(charIDToTypeID('In '), new File(data.path + "/" + data.name + ".tif"));
executeAction(charIDToTypeID('save'), desc, DialogModes.NO);
}; // end of saveTIF()
function getSubfolders(folder, mask)
{ // folder object, RegExp or string
if (mask == undefined) mask = "";
var sFolders = [];
var targetFolders = [];
sFolders[0] = folder;
for (var j = 0; j < sFolders.length; j++)
{
var procFiles = sFolders[j].getFiles();
for (var i = 0; i < procFiles.length; i++)
{
if (procFiles[i] instanceof Folder)
{
if (procFiles[i].fullName.search(mask) != -1) targetFolders.push(procFiles[i]);
sFolders.push(procFiles[i]);
getSubfolders(procFiles[i], mask);
}
}
}
return targetFolders
} // end of getSubfolders()
Have something to add?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now