Last active
February 16, 2016 16:04
-
-
Save birksy89/c88508063d8e082bdb58 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var inputFolder = Folder.selectDialog("Select a folder to process"); | |
var fileList = inputFolder.getFiles("*.*"); //Use whatever extension you want or no extension to select all files | |
// these are our values for the end result width and height (in pixels) of our image | |
//var fWidth = 1200; | |
//var fHeight = 1200; | |
var fWidth = prompt("Width", "", "Width2"); | |
var fHeight = prompt("Height", "", "Height2"); | |
var x = 0; | |
while (x < fileList.length) { | |
//alert(fileList.length); | |
open(fileList[x]) | |
// get a reference to the current (active) document and store it in a variable named "doc" | |
doc = app.activeDocument; | |
// change the color mode to RGB. Important for resizing GIFs with indexed colors, to get better results | |
doc.changeMode(ChangeMode.RGB); | |
// do the resizing. if height > width (portrait-mode) resize based on height. otherwise, resize based on width | |
if (doc.height > doc.width) { | |
doc.resizeImage(null, UnitValue(fHeight, "px"), null, ResampleMethod.BICUBIC); | |
} | |
else { | |
doc.resizeImage(UnitValue(fWidth, "px"), null, null, ResampleMethod.BICUBIC); | |
} | |
// call autoContrast and applySharpen on the active layer. | |
// if we just opened a gif, jpeg, or png, there's only one layer, so it must be the active one | |
doc.activeLayer.autoContrast(); | |
doc.activeLayer.applySharpen(); | |
// our web export options | |
var options = new ExportOptionsSaveForWeb(); | |
options.quality = 70; | |
options.format = SaveDocumentType.JPEG; | |
options.optimized = true; | |
//var newName = 'web-' + doc.name + '.jpg'; - This used to append the .jpg - It would do it to all files inc existing jpgs making them .jpg.jpg | |
var newName = 'web-' + doc.name; | |
var folder1 = Folder(doc.path + "/Resized"); | |
//Check if it exist, if not create it. | |
if (!folder1.exists) folder1.create(); | |
doc.exportDocument(File(doc.path + '/Resized/' + newName), ExportType.SAVEFORWEB, options); | |
//app.activeDocument.save() - This would save over the original file as well as the save command above. | |
//app.activeDocument.close(); - Save prompt comes up | |
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES); | |
x++; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment