Code Whisperer
Code Whisperer

Reputation: 23662

JSX Script to Output Image with Multiple Different Names in Photoshop

I am new to scripting in JSX for Photoshop and I am trying to figure out how to do the following:

I have a file, Lemons.psd.

I would like to output this file to four identical PNG files:

Lemons1.png
Lemons2.png
Lemons3.png
Lemons4.png

All that it is doing is appending something to the PSD name, and saving it as a PNG.

How would this be accomplished with JSX for Photoshop?

Upvotes: 0

Views: 496

Answers (1)

Anna Forrest
Anna Forrest

Reputation: 1741

Use this snippet...

var sourceFile = new File('/c/temp/image.png')
var destPath = '/c/temp/';
var doc = app.open(sourceFile);

for (var i = 1; i < 5; i++) {
        var options = new PNGSaveOptions();
        var outputFile = new File(destPath + sourceFile.name.match(/(.+)\.[^\.\/]+$/)[1] + i + '.png');

        app.activeDocument.saveAs(outputFile, options);
}

Upvotes: 2

Related Questions