Skip to main content
Participant
May 20, 2019
Question

File naming in a Photoshop Droplet

  • May 20, 2019
  • 2 replies
  • 387 views

Hi All

i am trying to produce a Photoshop Droplet that will take a square image, convert to RGB and then image size 4 different sizes and output them to a folder with the original filename with the pixel dimensions added to the end of the filename like this

EMG104869_120x120px.jpeg

The droplet needs to out put 4 different files to a folder at

720x720 pixels at 72ppi

360x360 pixels at 72ppi

208x208 pixels at 72ppi

100x100 pixels at 72ppi

Can anyone advise?

I suppose I need to use an Applescript or Javascript action to do this?

Thanks

Geoff

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
May 22, 2019
Inspiring
May 21, 2019

Hi,

Here is the javascript that will help you

function convertImageToRGB() {

    var idCnvM = charIDToTypeID("CnvM");

    var desc19 = new ActionDescriptor();

    var idT = charIDToTypeID("T   ");

    var idRGBM = charIDToTypeID("RGBM");

    desc19.putClass(idT, idRGBM);

    executeAction(idCnvM, desc19, DialogModes.NO);

}

function main() {

    var file = File.openDialog('Select File');

    app.open(file);

    var sizeArray = [720, 360, 208, 100];

    convertImageToRGB();

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

        resizeDocument(sizeArray, sizeArray);

        saveDifferentVersion(sizeArray, sizeArray);

    }

}

function resizeDocument(targetWidth, targetHeight) {

    resizeDocumentSide("width", targetWidth);

    resizeDocumentSide("height", targetHeight);

}

function resizeDocumentSide(side, value) {

    var descriptor = new ActionDescriptor();

    if (side == "width")

        descriptor.putUnitDouble(app.charIDToTypeID("Wdth"), app.charIDToTypeID("#Pxl"), value);

    if (side == "height")

        descriptor.putUnitDouble(app.charIDToTypeID("Hght"), app.charIDToTypeID("#Pxl"), value);

     descriptor.putBoolean(app.stringIDToTypeID("scaleStyles"), true);

    descriptor.putBoolean(app.charIDToTypeID("CnsP"), true);

    descriptor.putEnumerated(app.charIDToTypeID("Intr"), app.charIDToTypeID("Intp"), app.stringIDToTypeID("bicubicAutomatic"));

    app.executeAction(app.charIDToTypeID("ImgS"), descriptor, DialogModes.NO);

}

function saveDifferentVersion(width, height) {

    var outputFolder = Folder.desktop;

    var name = app.activeDocument.name.substr(0, app.activeDocument.name.lastIndexOf('.'));

    var url = outputFolder + "/" + name + "_" + width + "x" + height + "px.jpeg";

    var img = new JPEGSaveOptions();

    app.activeDocument.saveAs(new File(url), img, true, Extension.LOWERCASE);

}

main();

Thanks

Charu