I am just needing the script to output it as a jpg only (not psd or png)
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);
}