It’s easy enough to make a macro to output multiple sizes of jpgs into different folders, but if you want multiple sizes of the image in the same folder, what can you do? This.
//vars
var doc = app.activeDocument;
// get a reference to the active document and store it in a variable named "doc"
var fname = new String (doc.name);
//get filename of doc
fname = fname.substr (0, fname.lastIndexOf("."));
//remove extension
var folder = doc.path;
//get folder of doc
var folderStr = folder.toString() + "/jpg";
//name the subfolder to be created in current folder
var outfolder = new Folder (folderStr);
//make Folder object
if (!outfolder.exists) { //check if subfolder already exists
outfolder.create();
//create the subfolder if it doesn't exist
}
//functions
function resize(height) {
doc.resizeImage(null,UnitValue(height,"px"),null,ResampleMethod.BICUBICSHARPER);
//resize image to specified height, keeping aspect ratio
}
function saveForWeb(outputFolderStr, filename) {
var opts, file;
opts = new ExportOptionsSaveForWeb();
//create object for save for web options
opts.format = SaveDocumentType.JPEG;
//specify format option jpg
if (filename.length > 27) { //check filename length so it won't get trunctuated
file = new File(outputFolderStr + "/temp.jpg");
//temp file name because file name would be too long
activeDocument.exportDocument(file, ExportType.SAVEFORWEB, opts);
//export
file.rename(filename + ".jpg");
//rename temp file to the desired name
} else { //desired name is short enough
file = new File(outputFolderStr + "/" + filename + ".jpg");
activeDocument.exportDocument(file, ExportType.SAVEFORWEB, opts);
//export
}
}
//run
resize(1200);
saveForWeb(folderStr, fname + "-zoom");
resize(600);
saveForWeb(folderStr, fname + "-large");
resize(250);
saveForWeb(folderStr, fname);
If you wanted to use a predetermined folder instead of creating a subfolder, you could just change this:
var currentFolder = doc.path; //get folder of doc var folderStr = currentFolder.toString() + "/jpg"; //name the subfolder to be created in current folder
to this:
var folderStr = "/your/path/here" //use your desired folder for output