Skip to content

Instantly share code, notes, and snippets.

@kuyseng
Created May 26, 2012 04:52
Show Gist options
  • Save kuyseng/2792275 to your computer and use it in GitHub Desktop.
Save kuyseng/2792275 to your computer and use it in GitHub Desktop.
javascript: photoshop save as file type
function save_as_file_type(fileObj) { // { fileName, fileType, path, quality }
if (app.documents.length == 0) {
alert("Please have an 'photoshop' document before running this script.");
return;
}
var quality = fileObj.quality || 3, //default 3
path = fileObj.path || app.activeDocument.path,
document = fileObj.document || app.activeDocument,
fileName = document.name,
fileType = fileObj.fileType,
path = fileObj.path;
fileName = fileName.substr(0, fileName.lastIndexOf('.')); // remove file extension: x = x.replace(/\..+$/, '');
var newFile = new File( path + "/" + fileName);
switch(fileType.toLowerCase()) {
case "jpg":
case "jpeg":
var saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = quality;
break;
case "png":
var saveOptions = new PNGSaveOptions();
break;
default:
var saveOptions = new PhotoshopSaveOptions();
break;
};
document.saveAs(newFile, saveOptions, true, Extension.LOWERCASE);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment