1

My workflow contains creating multiple panoramas in Photoshop one by one. I have multiple folders, each with jpegs that have to be combined into a panorama and saved with a PSD extention.

Photoshop does a good job at producing the panorama, but I waste a lot of time in intervening at the repetitive steps of selecting folders and its contents, opening them in the panorama box and selecting the required panorama options (which includes checking reposition and unchecking blend images together) before photoshop does its photo-merging magic. Also, I waste time in the save dialogue box to save each image after the panorama is generated.

I wanted to know if there's a script that can automate this entire task. So that I provide the parent folder (which has the folders of photos that needed to be stitched) and leave the computer for hours as it processes the photomerge and saving the resultant PSD files without me having to sit next to it. I have a feeling that this is possible because all steps are repetitive.

Old forums have solutions to many similar issues, with wizards creating scripts for the same, but none of the links work now.

1
  • hello and welcome to GDSE. yes it should be possible with scripts i guess but your question is missing some points like how exactly you making such image and replacing and what type of layers you have etc. if possible you can share screenshot for better understanding :)
    – Mr.Online
    May 31, 2019 at 3:23

1 Answer 1

2

Here, I slightly modified this script by Mike Hale. This script will ask for a folder and then will process all subfolders with images. Things to change:

  1. Make sure path to your Photoshop Scripts folder is correct (line 2);
  2. This script is scanning for .png files, modify the extension in line 24 (folders[i].getFiles('*.png'););
  3. PSDs will be saved to each subfolder.

Result (I took some random google images for the test):

enter image description here

var runphotomergeFromScript = true; // must be before Photomerge include
//@includepath "/C/Program Files/Adobe/Adobe Photoshop CC 2019/Presets/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 = workFolder.getFiles(function(file)
    {
        return file instanceof Folder;
    });

    if (folders.length == 0) return false

    for (var i = 0; i < folders.length; i++)
    {

        var fList = folders[i].getFiles('*.png');

        // 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 = false; // 'Blend Images Together' checkbox in dialog
        photomerge.lensCorrection = false; // Geometric Distortion Correction'checkbox in dialog
        photomerge.removeVignette = false; // 'Vignette Removal' checkbox in dialog

        try
        {
            if (fList.length > 1)
            {
                photomerge.createPanorama(fList, false);
            }
        }
        catch (e)
        {
            alert(e + '\nLine: ' + e.line)
        }
        // saving
        var saveFile = {
            name: folders[i].name,
            path: fList[0].parent
        }

        savePSB(saveFile)
        saveTIF(saveFile)
        saveJPG(saveFile)
        savePSD(saveFile)

        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    }
})()

function savePSB(data)
{
    var desc = new ActionDescriptor();
    var descCompatibility = new ActionDescriptor();
    descCompatibility.putBoolean(stringIDToTypeID('maximizeCompatibility'), true);
    desc.putObject(charIDToTypeID('As  '), charIDToTypeID('Pht8'), descCompatibility);
    desc.putPath(charIDToTypeID('In  '), new File(data.path + "/" + data.name + ".psb"));
    executeAction(charIDToTypeID('save'), desc, DialogModes.NO);
}; // end of savePSB()

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 saveJPG(data)
{
    if (data.path == undefined) return false;
    data.name = data.name == undefined ? activeDocument.name : data.name;
    data.quality == undefined && data.quality = 75

    var options = new ExportOptionsSaveForWeb(),
        jpgFile = new File(data.path + '/' + data.name + '.jpg');
    options.format = SaveDocumentType.JPEG;
    options.quality = data.quality;
    activeDocument.exportDocument(jpgFile, ExportType.SAVEFORWEB, options);
}

function savePSD(data)
{
    var desc = new ActionDescriptor();
    var descOptions = new ActionDescriptor();
    descOptions.putBoolean(stringIDToTypeID('maximizeCompatibility'), true);
    desc.putObject(charIDToTypeID('As  '), charIDToTypeID('Pht3'), descOptions);
    desc.putPath(charIDToTypeID('In  '), new File(data.path + "/" + data.name + ".psd"));
    executeAction(charIDToTypeID('save'), desc, DialogModes.NO);
} // end of savePSD()
11
  • Thanks a ton for the script! It works great and does wonders to my workflow. I wish to thank you again for helping me out with this. It works well with all my required file types also. I wish to ask you two questions about the script. Firstly, is there a way that the filename of the saved psd gets changed to the name of the folder instead of "completed". And secondly, is there a way to save the file as a psb document or a tif document also? I tried playing around with the last few lines but it didn't seem to work.
    – Ab Pro
    Jun 10, 2019 at 9:53
  • I've updated my answer. This version will save both psb and tif with a name of a merge-files folder. If you need only one of the files simply remove line 58 or 59. Jun 11, 2019 at 8:10
  • Sergey! I wish to bother you again. What would be the changes to the code to save the final file as a jpeg?
    – Ab Pro
    Jun 18, 2019 at 8:18
  • 1
    Hi. I guess you can find this line in the script code and comment it to disable the message Jun 9, 2020 at 15:52
  • 1
    I did guide you: I wrote what to do :) Sorry, this answer wasn't supposed to be a free of charge scripting job Jun 10, 2020 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.