I am trying to figure out way for photoshop to tell me if an image is all black or not. A friend of mine found a way to create a 16 x 16 pixel selection and sample the color and determine if it is black or not. The selection then moves across the image and then to the next row. It continues this motions and if it finds a part of the image that is not black it immediately throws and error and the location of the infraction.
The problem is he wrote the script in javascript and while it works great with CS3, some of the terms are not recognized by CS.
Does anyone have any idea how I can accomplish this task using either javascript or applescript for Photoshop CS. THANKS!
the script is below:
var defaultRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var black = new SolidColor;
black.rgb.red = 0
black.rgb.green = 0
black.rgb.blue = 0
var height = 32;
var width = 32;
var horizontalBlocks = app.activeDocument.width/width;
var verticalBlocks = app.activeDocument.height/height;
//app.activeDocument.colorSamplers.removeAll();
var sampler = app.activeDocument.colorSamplers.add([0,0]);
for(a=0;a<horizontalBlocksverticalBlocks;a++)
{
var x1 = a%horizontalBlockswidth;
var y1 = Math.floor(a/horizontalBlocks)*height;
var x2 = x1+width;
var y2 = y1+height;
app.activeDocument.selection.select([[x1,y1],[x2,y1],[x2,y2],[x1,y2]]);
app.activeDocument.activeLayer.applyAverage()
sampler.move([x1+1,y1+1]);
var colorRef = sampler.color;
if(colorRef.isEqual(black))
{
}
else{
alert(“difference found at [” + x1 + “,” + y1 + “]”)
break
}
}
preferences.rulerUnits = defaultRulerUnits;