Skip to content

Instantly share code, notes, and snippets.

@jasonsturges
Created June 16, 2016 19:22
Show Gist options
  • Save jasonsturges/a55f5e57224021551fbb80dddaec9f0d to your computer and use it in GitHub Desktop.
Save jasonsturges/a55f5e57224021551fbb80dddaec9f0d to your computer and use it in GitHub Desktop.
Scale images to multiple sizes in Photoshop using JSX scripted batch processing automation
#target "photoshop"
if (BridgeTalk.appName == "photoshop") {
app.bringToFront();
var inputFolder = Folder.selectDialog("Select the folder containing photos to be resized."),
imageSizes = [2048, 1024, 512, 256];
if (inputFolder != null) {
var fileList = inputFolder.getFiles(/\.(jpg|jpeg|tif|psd|)$/i);
for (var n = 0; n < imageSizes.length; n++) {
var outputFolder = new Folder(decodeURI(inputFolder) + "/export-" + imageSizes[n]);
if (outputFolder.exists == false)
outputFolder.create();
for (var i = 0; i < fileList.length; i++) {
if (fileList [i] instanceof File) {
var document = open(fileList [i]);
var documentName = fileList [i].name.slice(0, -4);
while (app.documents.length) {
var newFile = new File(decodeURI(outputFolder) + "/" + documentName + ".jpg");
document.flatten();
if (document.width > document.height) {
document.resizeImage(null, UnitValue(imageSizes[n], "px"), null, ResampleMethod.BICUBICSHARPER);
} else {
document.resizeImage(UnitValue(imageSizes[n], "px"), null, null, ResampleMethod.BICUBICSHARPER);
}
var exportOptions = new JPEGSaveOptions();
exportOptions.embedColorProfile = true;
exportOptions.quality = 8;
document.saveAs(newFile, exportOptions, true, Extension.LOWERCASE);
document.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment