Created
June 16, 2016 19:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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