Skip to main content
Known Participant
March 15, 2023
Answered

Please help with simple automation - add filename text below image

  • March 15, 2023
  • 3 replies
  • 9330 views

Would you kindly help me automate the following operations? I have to modify 547 images, and it'll take me 10-12 hours by hand. I'm embedding the image filename below the image for placement on a website.

FWIW, I'm an event photographer. I work almost exclusively in Lightroom Classic and DxO PhotoLab and have long since forgotten most of what I knew about Photoshop 20 years ago.

 

  1. Open 1800x1200px jpeg and place it at the top of an 1800x1300px canvas (with transparent background).
  2. Create text field, centered horizontally in the bottom 100px band, and paste image filename.
  3. Save with image filename as PSD and PNG.

 

 

 

 

Any suggestions would be most welcome. Thanks! An example file is attached.

This topic has been closed for replies.
Correct answer Stephen Marsh

I am just needing the script to output it as a jpg only (not psd or png)


quote

I am just needing the script to output it as a jpg only (not psd or png)


By @Shoua5C98

 

Try this script, it should be close enough and can be easily tweaked if you need it "pixel perfect" to your samples. Let me know if there are any major issues that you can't figure out:

 

/*
Batch Add Filename to Lower Right of Canvas.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/please-help-with-simple-automation-add-filename-text-below-image/td-p/13652732
v1.0, 1st August 2023, Stephen Marsh
*/

#target photoshop

// Set the input and output folders
var inputFolder = Folder.selectDialog("Please select the input folder:");
var outputFolder = Folder.selectDialog("Please select the output folder:");

// Limit the input files, add or remove extensions as required
var fileList = inputFolder.getFiles(/\.(webp|tif|tiff|jpg|jpeg|psd|psb|png)$/i);
fileList.sort();

// Set the dialog and ruler options
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

// Set the file processing counter
var fileCounter = 0;

// Process the input files
for (var i = 0; i < fileList.length; i++) {

    open(fileList[i]);

    //activeDocument.resizeImage(null, null, 300, ResampleMethod.NONE);
    var docName = activeDocument.name.replace(/\.[^\.]+$/, '');
    var textLayer = activeDocument.artLayers.add();
    textLayer.kind = LayerKind.TEXT;
    var theText = textLayer.textItem;
    var theColor = new SolidColor;
    theColor.rgb.red = 255;
    theColor.rgb.green = 255;
    theColor.rgb.blue = 255;
    textLayer.textItem.color = theColor;
    theText.position = [500, 500];
    theText.justification = Justification.RIGHT;
    //theText.font = 'Arial-Regular';
    theText.font = 'ArialMT';
    theText.size = 8;
    theText.contents = docName;
    alignToSel('AdRg');
    alignToSel('AdBt');
    activeDocument.activeLayer.translate(-25, -25);
    var saveJPEGName = File(outputFolder + "/" + docName + ".jpg");
    saveJPEG(saveJPEGName);
    activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    fileCounter++;
}

app.displayDialogs = savedDisplayDialogs;
app.preferences.rulerUnits = originalRulerUnits;

alert('Script completed!' + '\n' + fileCounter + ' files saved to:' + '\r' + outputFolder.fsName);


// FUNCTIONS //

function alignToSel(method) {
    /* https://gist.github.com/MarshySwamp/df372e342ac87854ffe08e79cbdbcbb5 */

    //www.ps-scripts.com/viewtopic.php?f=66&t=7036&p=35273&hilit=align+layer#p35273
    /* 
    //macscripter.net/viewtopic.php?id=38890
    AdLf = Align Left
    AdRg = Align Right
    AdCH = Align Centre Horizontal
    AdTp = Align Top
    AdBt = Align Bottom
    AdCV = Align Centre Vertical
    */

    app.activeDocument.selection.selectAll();

    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    desc.putReference(charIDToTypeID("null"), ref);
    desc.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("ADSt"), charIDToTypeID(method));
    try {
        executeAction(charIDToTypeID("Algn"), desc, DialogModes.NO);
    } catch (e) { }

    app.activeDocument.selection.deselect();
}

function saveJPEG(saveFile) {
    var jpgOptns = new JPEGSaveOptions();
    jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgOptns.embedColorProfile = true;
    jpgOptns.matte = MatteType.NONE;
    jpgOptns.quality = 10;
    activeDocument.saveAs(saveFile, jpgOptns, true, Extension.LOWERCASE);
}

 

3 replies

Known Participant
March 16, 2023

Thanks for the suggestion, but wouldn't this just append the same single filename entered in step 5 to all 547 images? I want each image to have its own filename appended. In any case, I got it done with Variables, as noted above.

jane-e
Community Expert
Community Expert
July 31, 2023
quote

Thanks for the suggestion, but wouldn't this just append the same single filename entered in step 5 to all 547 images?

By @JacquesCornell

 

The message you replied to used ChatGPT and contained a spam link. It has been removed from the thread.

Jane

c.pfaffenbichler
Community Expert
Community Expert
March 15, 2023

This is an old Script by Paul Riggott that adds the document name bottom right and saves psds. 

So you may need to adapt it to your specific needs, but is should demonstrate the workability.  

 

// by paul riggott;
processFiles();
function processFiles(){
//// AMEND TO SUIT///////////////////////////////////////////////////////////////////////////
var fontSize = 24;  // Font Size
var fontName = "Helvetica"; 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inputFolder = Folder.selectDialog("Please select the folder with Files to process");
if(inputFolder == null) return;
outputFolder = Folder.selectDialog("Please select the output folder");
if(outputFolder == null) return;
var fileList = inputFolder.getFiles(/\.(jpg|psd)$/i);
app.displayDialogs = DialogModes.NO;     
var strtRulerUnits = app.preferences.rulerUnits;       
var strtTypeUnits = app.preferences.typeUnits;       
app.preferences.rulerUnits = Units.PIXELS;       
app.preferences.typeUnits = TypeUnits.PIXELS; 
for(var a =0 ; a<fileList.length;a++){
 var file = fileList[a];
 open(file);
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var textColor = new SolidColor(); 
textColor.rgb.hexValue = '000000';  
var newTextLayer = activeDocument.artLayers.add(); 
newTextLayer.kind = LayerKind.TEXT; 
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = textColor; 
newTextLayer.textItem.font = fontName;
newTextLayer.textItem.size = fontSize; 
newTextLayer.textItem.contents = Name;
align("AdBt");
align("AdRg");
activeDocument.activeLayer.translate (-5, -5)
var fileName =activeDocument.name.match(/(.*)\.[^\.]+$/)[1];
var saveFile = File(outputFolder + "/" +Name + ".psd");
SavePSD(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); 
}
preferences.rulerUnits = strtRulerUnits;
function align(method) { 
activeDocument.selection.selectAll();
   var desc = new ActionDescriptor();
           var ref = new ActionReference();
           ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) ); 
       desc.putReference( charIDToTypeID( "null" ), ref ); 
       desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
    try{
   executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO ); 
   }catch(e){}
   activeDocument.selection.deselect();
};
function SavePSD(saveFile){ 
psdSaveOptions = new PhotoshopSaveOptions(); 
psdSaveOptions.embedColorProfile = true; 
psdSaveOptions.alphaChannels = true;  
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE); 
}
}

 

 

Known Participant
March 15, 2023

For my poor brain, this might as well be written in Greek and encrypted. I'm a photographer, not a coder.

Stephen Marsh
Community Expert
Community Expert
July 31, 2023

I tried all the scripts listed here and none of them quite work for me. I am looking for a script that will give me the file name on the bottom without a white part being added, outputted as a jpg. My images are 300 dpi and usually sized to 5"x7", sometimes 8"x10". Is there a script for that?

 


As you have found, this is very much specific to the user and their workflow, it isn't generic.

 

Can you attach a layered PSD to clearly illustrate?

Inspiring
March 15, 2023

I use Photoshop Variables for something like this. It has saved me a ton of time when creating sports cards, greeting cards, calendars, ads, and more.

https://helpx.adobe.com/photoshop/using/creating-data-driven-graphics.html

Known Participant
March 15, 2023

Thanks. I'm absorbing this tutorial. One question not answered there: How do I create a text variable data set comprising the filenames of all the images in a folder?

Known Participant
March 15, 2023

Also, how do I creat a pixel variable data set comprising all the images in a folder?

I've created a templace with a Background layer, a Filename text layer and an Image layer. Now I want PS to open the first image in the folder, paste it into the Image layer, then scrape the filename and paste it into the Filename layer, and save the result as a PSD.