Created
January 19, 2012 19:24
-
-
Save commadelimited/1641963 to your computer and use it in GitHub Desktop.
Scripting Photoshop with ExtendScript
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
// bring Photoshop into focus | |
// This also allows you to simply double click the JSX file | |
#target photoshop | |
// set some default variables | |
var docRef = app.activeDocument; | |
// remember this is JavaScript. That means I can take | |
// input from a user in the form of a prompt. Awesome right? | |
var fileName = prompt('Please enter base file name', docRef.name); | |
var basePath = '/Users/andymatthews/Desktop/goba/Application Design /Final/'; | |
// set options for saving document | |
var webOptions = new ExportOptionsSaveForWeb(); | |
webOptions.format = SaveDocumentType.PNG; | |
webOptions.PNG8 = false; | |
webOptions.transparency = true; | |
webOptions.interlaced = 0; | |
webOptions.includeProfile = false; | |
webOptions.optimized = true; | |
// take a snapshot to use for reverting | |
var savedState = docRef.activeHistoryState; | |
// save 2.0 image | |
docRef.exportDocument(getFileName('high'), ExportType.SAVEFORWEB,webOptions); | |
// resize to 75% | |
docRef.resizeImage('75%','75%'); | |
// save 1.5 image | |
docRef.exportDocument(getFileName('med'), ExportType.SAVEFORWEB,webOptions); | |
// revert back to pre-resized state | |
docRef.activeHistoryState = savedState; | |
// resize to 50% | |
docRef.resizeImage('50%','50%'); | |
// save 1.0 image | |
docRef.exportDocument(getFileName('low'), ExportType.SAVEFORWEB,webOptions); | |
// revert back to pre-resized state | |
docRef.activeHistoryState = savedState; | |
function getFileName(size) { | |
// accepts high, med, low | |
var sizes = { | |
'high': ['2.0/','@2x.png'], | |
'med': ['1.5/','.png'], | |
'low': ['1.0/','.png'] | |
}; | |
return new File(basePath + sizes[size][0] + fileName + sizes[size][1]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment