0

Trying to export multiple images from Photoshop. Current script works fine but I really need it to pad the numbers out, so instead of just "1" on the layer I get "001" for instance.

var directory = 'C:/Thumbs/';
var imageName = 'Thumb';
var numImages = 10;

function SaveJPEG(saveFile){  
var doc = activeDocument;  
if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;  
jpgSaveOptions = new JPEGSaveOptions();  
jpgSaveOptions.embedColorProfile = true;  
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;  
jpgSaveOptions.matte = MatteType.NONE;  
jpgSaveOptions.quality = 8;   
activeDocument.saveAs(new File(saveFile), jpgSaveOptions, true,Extension.LOWERCASE);  
} 

var layer = activeDocument.layers[0];

if (layer.kind == 'LayerKind.TEXT') {
  for (var i=1; i <= numImages; i++) {
    layer.textItem.contents = i.toString();
    SaveJPEG(directory + imageName + '_'+ i +'.jpg');
  };
};
jonrsharpe
  • 99,167
  • 19
  • 183
  • 334

1 Answers1

-1

To pad the image number to a width of 3, you may try:

var imageNum = '000' + i;
imageNum = imageNum.substr(imageNum.length - 3); 
SaveJPEG(directory + imageName + '_'+ imageNum +'.jpg');
Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263