@EmojiStickers.com
Try this script. The template document must be open. You will be prompted to select the input folder containing the source emoji PNG files. You will be prompted to select the output folder to save the new combined PNG files to.
/*
Batch Emoji Mockup.jsx
v1.0 - 14th June 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/looking-for-a-script-or-action-to-batch-process-3400-files-need-help/td-p/14680348
*/
#target photoshop
if (app.documents.length) {
(function () {
try {
// Select the source files
/*
var theFiles = File.openDialog('Select the file/s:', Multiselect = true);
if (theFiles === null) {
alert('Script cancelled!');
return;
}
*/
// Select the input folder
var theFiles = Folder.selectDialog("Select the folder containing the emoji PNG files:");
if (theFiles === null) {
alert('Script cancelled!');
return;
}
var fileList = theFiles.getFiles(/\.(png)$/i);
fileList.sort();
// Select the output folder
var outputFolder = Folder.selectDialog("Please select the output folder:");
if (outputFolder === null) {
alert('Script cancelled!');
return;
}
// Hide the Photoshop panels
app.togglePalettes();
// Script running notification window - courtesy of William Campbell
// https://www.marspremedia.com/download?asset=adobe-script-tutorial-11.zip
// https://youtu.be/JXPeLi6uPv4?si=Qx0OVNLAOzDrYPB4
var working;
working = new Window("palette");
working.preferredSize = [300, 80];
working.add("statictext");
working.t = working.add("statictext");
working.add("statictext");
working.display = function (message) {
this.t.text = message || "Script running, please wait...";
this.show();
app.refresh();
};
working.display();
// Set the file counter
var counter = 0;
// Get and set the ruler units
var origRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// Set the active doc as the template doc
var templateDoc = app.activeDocument;
var templateDocName = app.activeDocument.name;
// Ensure that the Hand Bottom layer is active
if (app.activeDocument.activeLayer.name != 'Hand Bottom') {
app.activeDocument.activeLayer = app.activeDocument.layers.getByName('Hand Bottom');
}
// Remove unnecessary metadata
removeDocumentAncestorsMetadata();
removeCRSmetadata();
removeXMPmetadata();
// Loop over the files
for (var i = 0; i < fileList.length; i++) {
// Open each selected file
app.open(File(fileList[i]));
// Set the sourceDoc as the active document
var sourceDoc = app.activeDocument;
// Select the source layer
app.activeDocument.activeLayer = app.activeDocument.layers[0];
// Duplicate the source layer to the template doc
dupeLayer(templateDocName, app.activeDocument.name.replace(/\.[^\.]+$/, ''));
// Set the template doc as the active document
app.activeDocument = templateDoc;
// Centre the duped layer on the template canvas
app.activeDocument.activeLayer.translate(app.activeDocument.width / 2 - (app.activeDocument.activeLayer.bounds[0] + app.activeDocument.activeLayer.bounds[2]) / 2,
app.activeDocument.height / 2 - (app.activeDocument.activeLayer.bounds[1] + app.activeDocument.activeLayer.bounds[3]) / 2);
// Resize to 21% scale
scaleLayer(21.0, 21.0);
// Close the source doc
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
// File name from emoji layer name
var docName = app.activeDocument.activeLayer.name.replace(/\.[^\.]+$/, '');
// Save as PNG options
var pngFile = new File(outputFolder + "/" + docName + ".png");
var pngOptions = new PNGSaveOptions();
pngOptions.compression = 9; // 0-9
pngOptions.interlaced = false;
app.activeDocument.saveAs(pngFile, pngOptions, true, Extension.LOWERCASE);
// Delete the emoji layer
app.activeDocument.activeLayer.remove();
// Increment the file counter
counter++
}
// Restore the original ruler units
app.preferences.rulerUnits = origRulerUnits;
// Close the template doc
templateDoc.close(SaveOptions.DONOTSAVECHANGES);
// Ensure Photoshop has focus before closing the running script notification window
app.bringToFront();
working.close();
// End of script notification
app.beep();
alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder);
// Restore the Photoshop panels
app.togglePalettes();
// Functions
function dupeLayer(targetDocName, sourceLayerName) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
var reference2 = new ActionReference();
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(s2t("null"), reference);
reference2.putName(s2t("document"), targetDocName);
descriptor.putReference(s2t("to"), reference2);
descriptor.putString(s2t("name"), sourceLayerName);
descriptor.putList(s2t("ID"), list);
executeAction(s2t("duplicate"), descriptor, DialogModes.NO);
}
function scaleLayer(width, height) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
descriptor.putReference(s2t("null"), reference);
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);
descriptor.putUnitDouble(s2t("width"), s2t("percentUnit"), width);
descriptor.putUnitDouble(s2t("height"), s2t("percentUnit"), height);
descriptor.putEnumerated(s2t("interfaceIconFrameDimmed"), s2t("interpolationType"), s2t("bicubicSmoother"));
executeAction(s2t("transform"), descriptor, DialogModes.NO);
}
function removeXMPmetadata() {
//https://community.adobe.com/t5/photoshop/script-to-remove-all-meta-data-from-the-photo/td-p/10400906
if (!documents.length) return;
if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
XMPUtils.removeProperties(xmp, "", "", XMPConst.REMOVE_ALL_PROPERTIES);
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
function removeCRSmetadata() {
//community.adobe.com/t5/photoshop/remove-crs-metadata/td-p/10306935
if (!documents.length) return;
if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
XMPUtils.removeProperties(xmp, XMPConst.NS_CAMERA_RAW, "", XMPConst.REMOVE_ALL_PROPERTIES);
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
function removeDocumentAncestorsMetadata() {
whatApp = String(app.name); //String version of the app name
if (whatApp.search("Photoshop") > 0) { //Check for photoshop specifically, or this will cause errors
if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
// Begone foul Document Ancestors!
xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
}
} catch (e) {
alert('Error!' + '\r' + e + ', Line: ' + e.line);
}
})();
} else {
alert('A document must be open to run this script!');
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html