Skip to main content
Participating Frequently
February 4, 2011
Question

multiple images batch resize and rename

  • February 4, 2011
  • 1 reply
  • 2311 views

ok so im new to javascript and just know how to navigate through it. My task is to upload many pics to the web in diferent squared dimentions(50,80,100,150,250,400,600) So what i need to do is take the master (which I squared already) and output all those file sizes and with corisponding file extention name ( 150px pic has file name "originalname_150.png) I can do this in batch with actions but have to do this with each file size. I need it to do it to all files in folder then make sub folder with all sizes listed.

I took this and edited it, probally off

// size
var fWidth = 600;
var fHeight = 600;

// our web export options
var options = new ExportOptionsSaveForWeb(); <------ says it dosnt have constructor in extendscript toolkit
options.quality = 70;
options.format = SaveDocumentType.PNG;

var newName = doc.name+ '_400' + '.png';

doc.exportDocument(File(doc.path+'/'+newName));

can i just make a one for one size that resizes and names and saves, then copy paste it below with new size, would that work?

anything will help guys

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
February 4, 2011

If the document is square this should be close...


#target photoshop
main();
function main(){
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var Name = doc.name.replace(/\.[^\.]+$/, '');
var Path = decodeURI(doc.path);
doc.resizeImage(600, undefined, undefined, ResampleMethod.BICUBICSHARPER);
var saveFile = File(Path +"/"+Name+"_600.png");
sfwPNG24(saveFile);
doc.resizeImage(400, undefined, undefined, ResampleMethod.BICUBICSHARPER);
var saveFile = File(Path +"/"+Name+"_400.png");
sfwPNG24(saveFile);
doc.resizeImage(250, undefined, undefined, ResampleMethod.BICUBICSHARPER);
var saveFile = File(Path +"/"+Name+"_250.png");
sfwPNG24(saveFile);
doc.resizeImage(150, undefined, undefined, ResampleMethod.BICUBICSHARPER);
var saveFile = File(Path +"/"+Name+"_150.png");
sfwPNG24(saveFile);
doc.resizeImage(100, undefined, undefined, ResampleMethod.BICUBICSHARPER);
var saveFile = File(Path +"/"+Name+"_100.png");
sfwPNG24(saveFile);
doc.resizeImage(80, undefined, undefined, ResampleMethod.BICUBICSHARPER);
var saveFile = File(Path +"/"+Name+"_80.png");
sfwPNG24(saveFile);
doc.resizeImage(50, undefined, undefined, ResampleMethod.BICUBICSHARPER);
var saveFile = File(Path +"/"+Name+"_50.png");
sfwPNG24(saveFile);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
app.preferences.rulerUnits = startRulerUnits;
}
function sfwPNG24(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 70;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}

Participating Frequently
February 4, 2011

holy crap!! THANK YOU. you just saved me hours of work. I'll try it out later but it looks good

Participating Frequently
February 4, 2011

ok that works great. now im trying to figure out how to have the script put the out put files into a sub folder "web". And with this script is it possible to put in a droplet or run in bridge?