Skip to main content
Participating Frequently
April 18, 2023
Question

Batch processing multiple images over a single image?

  • April 18, 2023
  • 3 replies
  • 2338 views

I have a single background layer that shows a static website image, a billboard image, and an image of a restaurant menu. I would like to test 30 different logos on each asset- so importing logo #1 in all 3 places, and exporting that entire image as a jpeg. Then replacing logo #1 with logo #2 in all 3 places, and exporting that entire image as another jpeg. I am beginner level at actions and the Automate/batch function in Photoshop. Can this be done using those tools, or is something more complex (ie, custom script) required? Thank you.

This topic has been closed for replies.

3 replies

Bojan Živković11378569
Community Expert
Community Expert
April 22, 2023

Are you familiar with data driven graphics https://helpx.adobe.com/photoshop/using/creating-data-driven-graphics.html

It can not output JPEG although its easy to convert PSD to JPEG. It is excellent option for batch replacements or placements without coding skills.

 

There is a way and using actions I believe but its rather complicated to explain and execute for beginner.

Stephen Marsh
Community Expert
Community Expert
April 20, 2023

@Teresa24314189x5jg 

 

Unfortunately, I only have time to automate part of this for now. This is possible to fully automate, however, I probably wont be able to get to it for another couple of days. Although it is tedius to manually select 30 logos, that is the best that I can offer for now.

 

With your template PSD open, the following script will ask for you to select a single logo at a time. It will then place linked into each of your frames and automatically save out a JPEG named after the logo file to the same folder as the PSD.

 

Perhaps another scripter could extend the code to batch process all logos...

 

/*
Single Logo to Multiple Layer Frames to JPEG.jsx
v1.0 - 21st April 2023, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/batch-processing-multiple-images-over-a-single-image/m-p/13737593
*/

#target photoshop

if (app.documents.length > 0) {

    try {
        var docPath = activeDocument.path.fsName;
    } catch (e) {
        var docPath = Folder.selectDialog('The doc has never been saved, please select the save folder:');
    }

    function main() {

        var theLogo = File.openDialog("Select the logo:");
        var docName = theLogo.displayName.replace(/\.[^\.]+$/, '');

        for (var i = 0; i < activeDocument.layers.length; i++) {
            try {
                activeDocument.activeLayer = activeDocument.layers[i];
                if (activeDocument.activeLayer.typename === "LayerSet" && isFrame() === true) {
                    placeInFrame(new File(theLogo));
                    align("ADSLefts");
                    align("ADSTops");
                }
            } catch (e) {
                alert("Error!" + "\r" + e + ' ' + e.line);
            }
        }

        var saveFileJPEG = new File(docPath + '/' + docName + '.jpg');
        if (saveFileJPEG.exists) {
            // true = 'No' as default active button
            if (!confirm("File exists, overwrite: Yes or No?", true))
                // throw alert("Script cancelled!");
                throw null;
        }
        SaveForWeb(saveFileJPEG);
    }
} else {
    alert("You must have a document open to use this script!");
}
activeDocument.suspendHistory('Single Undo...', 'main()');


///// FUNCTIONS /////

function placeInFrame(thePath) {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    descriptor.putInteger(s2t("ID"), 128);
    descriptor.putPath(s2t("null"), thePath);
    descriptor.putBoolean(s2t("linked"), true);
    descriptor.putEnumerated(s2t("freeTransformCenterState"), s2t("quadCenterState"), s2t("QCSAverage"));
    descriptor2.putUnitDouble(s2t("horizontal"), s2t("pixelsUnit"), 0);
    descriptor2.putUnitDouble(s2t("vertical"), s2t("pixelsUnit"), 0);
    descriptor.putObject(s2t("offset"), s2t("offset"), descriptor2);
    executeAction(s2t("placeEvent"), descriptor, DialogModes.NO);
}

function align(alignPos) {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(s2t("null"), reference);
    descriptor.putEnumerated(s2t("using"), s2t("alignDistributeSelector"), s2t(alignPos));
    descriptor.putBoolean(s2t("alignToCanvas"), false);
    executeAction(s2t("align"), descriptor, DialogModes.NO);
}

function isFrame() {
    // modified from a script by greless with hints from jazz-y!
    // returns true or false
    try {
        var d = new ActionDescriptor();
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID('layer'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'));
        var options = executeActionGet(r);
        return options.hasKey(stringIDToTypeID('framedGroup')); // test for the required key
    } catch (e) {
        alert("Error!" + "\r" + e + ' ' + e.line);
    }
}

function SaveForWeb(saveFileJPEG) {
    var sfwOptions = new ExportOptionsSaveForWeb();
    sfwOptions.format = SaveDocumentType.JPEG;
    sfwOptions.includeProfile = true;
    sfwOptions.interlaced = 0;
    sfwOptions.optimized = true;
    sfwOptions.quality = 70;
    app.activeDocument.exportDocument(saveFileJPEG, ExportType.SAVEFORWEB, sfwOptions);
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run:

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

Participating Frequently
April 21, 2023

Wow, thank you so much! I really appreciate this. I am very impressed. I still have a long way to learn about how much Photoshop's built automation can do vs. scripting.

Stephen Marsh
Community Expert
Community Expert
April 22, 2023

@Teresa24314189x5jg – Please do let me know how you go with the script.

 

I'm stuck automating this further with a script to automate this for multiple logos in a single run. This is why I offered the less-than-ideal fallback approach of manually selecting each logo separately.

Stephen Marsh
Community Expert
Community Expert
April 18, 2023

Although possible with a batch action (adding the static images, not the variable images which are handled by the batch), it would be easier with a script (adding the variable images to the static images).

 

Providing a before and after sample image would help to illustrate.

 

Even better, providing sample files would be good.

Participating Frequently
April 19, 2023

So placing Logo 1 in all 3 areas in "Master Template", then exporting that whole image as a jpeg. Then placing Logo 2 in all 3 areas (get rid of Logo 1), then exporting that whole image as a jpeg and so on. For like 30 different logos. But the gray boxes all remain the same.

Stephen Marsh
Community Expert
Community Expert
April 20, 2023

Thank you for the examples.

 

Is the PSD file representative of your production files? It uses a single layer, however, I just wanted to check that you were not using layer sets or an artboard/s?

 

The PSD file uses frames (frame tool) to size the PNG images. The PNG images are all square, however, the frames are rectangles.