Skip to content

Instantly share code, notes, and snippets.

@acspike
Last active December 31, 2015 14:19
Show Gist options
  • Save acspike/7999179 to your computer and use it in GitHub Desktop.
Save acspike/7999179 to your computer and use it in GitHub Desktop.
Save in two sizes
#target photoshop
main();
function main() {
if(!documents.length) return;
var doc = app.activeDocument;
try{
var Path = activeDocument.path;
}
catch(e){
var Path = "~/desktop";
}
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var layerName = app.activeDocument.activeLayer.name.replace(/[:\/\\*\?\"\<\>\|]/g, "_");
var sizes = [1500, 400];
var startState = doc.activeHistoryState;
var initialPrefs = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var saveFile = null;
for (var i=0; i<sizes.length; i++) {
saveFile = new File(Path + "/" + Name + "-" + layerName + "-" + sizes[i].toString() + ".jpg");
doc.resizeImage(sizes[i], sizes[i], null, ResampleMethod.BICUBICSHARPER);
SaveForWeb(saveFile,80);
}
doc.activeHistoryState = startState;
}
function SaveForWeb(saveFile,jpegQuality) {
var sfwOptions = new ExportOptionsSaveForWeb();
sfwOptions.format = SaveDocumentType.JPEG;
sfwOptions.includeProfile = false;
sfwOptions.interlaced = 0;
sfwOptions.optimized = true;
sfwOptions.quality = jpegQuality;
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment