Copy link to clipboard
Copied
I have compiled a script that detects if a given file is completely blank and if it is it creates a 2px x 2px black box and then trims down to it.
The issue i am having is if a file is entirely white (like a white box on a transparent canvas) the script thinks the file is empty and creates a 2px x 2px box.
Cant figure out how to make the histogram understand white, though through my understanding of histogram is it sees it as a black/white image?
#target photoshop
var doc = activeDocument
app.preferences.rulerUnits = Units.PIXELS;
var tally = 0;
var empty = false;
for(var j=0;j<doc.channels.length;j++)
{
var h = doc.channels
.histogram; for (i=0;i<h.length;i++){
if(h == parseInt(doc.width*doc.height))
{
empty = true
var boxFill = new SolidColor();
boxFill.rgb.red = 0;
boxFill.rgb.green = 0;
boxFill.rgb.blue = 0;
var selectionPX = [
[0,0],
[0,2],
[2,2],
[2,0]
]
doc.selection.select(selectionPX);
doc.selection.fill (boxFill);
doc.selection.deselect ();
}
}
if(empty)
{
tally++;
}
empty = false;
}
if (tally!=doc.channels.length)
{
doc.trim(TrimType.TRANSPARENT)
};
var blank = true;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDTo
Copy link to clipboard
Copied
var blank = true;
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));
r1.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("merged"));
d.putReference(stringIDToTypeID("to"), r1);
try { executeAction(stringIDToTypeID("set"), d, DialogModes.NO); } catch(e) { blank = false; }
if (blank) try { app.activeDocument.selection.bounds; blank = false; } catch (e) { }
app.activeDocument.selection.deselect();
alert(blank);
Copy link to clipboard
Copied
That works!
Curious to learn more about what ActionDescriptor and ActionReference with putProperty/putReference, Any good links you could recommend?
Thanks!