Create fill layer white/black depending on general colour
Is there a way to write a script that will create a new fill layer dependant on the colour of the image placed in the file?
So if the image is mainly white, create a grey fill layer, or mostly black, create a white fill layer? Or is there a way to allow the user to pick the colour of the fill layer?
I currently have this as part of my script but was wondering if it could be more adaptive.
function createFill() {
var fillColor = new SolidColor();
fillColor.rgb.red = 255;
fillColor.rgb.green = 255;
fillColor.rgb.blue = 255;
var newLayer = doc.artLayers.add();
newLayer.name = "fill " + (i + 1);
doc.selection.fill(fillColor);
newLayer.move(newLayer, ElementPlacement.PLACEAFTER);
var fillLayer = doc.activeLayer;
fillLayer.move(doc.layers[doc.layers.length-1], ElementPlacement.PLACEAFTER);
}