Skip to content

Instantly share code, notes, and snippets.

@allanwhite
Last active May 6, 2024 05:19
Show Gist options
  • Save allanwhite/7268828 to your computer and use it in GitHub Desktop.
Save allanwhite/7268828 to your computer and use it in GitHub Desktop.
This is a Photoshop .jsx script that will iterate & change a number in a text layer, and save-to-web files in a preset path.
function sfwPNG24(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
/*
Incrementing a number inside a text layer then Saving it in PNG
*/
var layer = activeDocument.layers[0];
var filePath = '~/Documents/Pictures/'; // your file path here
var fileNamePrefix = 'icon-pin-';
/* I'm having problems with PS shrinking the font size as it runs through the script. Hardcoding it for now. */
if (layer.kind == 'LayerKind.TEXT') {
for (var i=1; i < 100; i++) {
layer.textItem.contents = i.toString();
layer.textItem.size = 32;
sfwPNG24( filePath + fileNamePrefix + i +'.png');
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment