Adobe Photoshop CS3
JavaScript Scripting Reference
JavaScript Object Reference 75
// Set Adobe Photoshop CS3 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO
// if there are no documents open then try to open a sample file
if (app.documents.length == 0) {
open(File(app.path + "/Samples/Fish.psd"))
}
// get a reference to the working document
var docRef = app.activeDocument
// create the output file
// first figure out which kind of line feeds we need
if ($.os.search(/windows/i) != -1) {
fileLineFeed = "windows"
} else {
fileLineFeed = "macintosh"
}
// create the output file accordingly
fileOut = new File("~/Desktop/Histogram.log")
fileOut.lineFeed = fileLineFeed
fileOut.open("w", "TEXT", "????")
// write out a header
fileOut.write("Histogram report for " + docRef.name)
// find out how many pixels I have
var totalCount = docRef.width.value * docRef.height.value
// more info to the out file
fileOut.write(" with a total pixel count of " + tota "\n")
// channel indexer
var channelIndex = 0
// remember which channels are currently active
var activeChannels = app.activeDocument.activeChannels
// document histogram only works in these modes
if (docRef.mode == DocumentMode.RGB ||
docRef.mode == DocumentMode.INDEXEDCOLOR ||
docRef.mode == DocumentMode.CMYK) {
// activate the main channels so we can get the documents histogram
TurnOnDocumentHistogramChannels(docRef)
// Output the documents histogram
OutputHistogram(docRef.histogram, "Luminosity", fileOut)
}
// local reference to work from
var myChannels = docRef.channels
// loop through each channel and output the histogram
for (var channelIndex = 0; channelIndex < myChannels.length; chann+) {