Skip to main content
Participating Frequently
July 15, 2017
Question

Create fill layer white/black depending on general colour

  • July 15, 2017
  • 3 replies
  • 1394 views

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);

    }

This topic has been closed for replies.

3 replies

c.pfaffenbichler
Community Expert
Community Expert
July 16, 2017
davescm
Community Expert
Community Expert
July 15, 2017

Hi

I've moved your post to the Photoshop Scripting forum where you are more likely to get answers to your question

Dave

c.pfaffenbichler
Community Expert
Community Expert
July 15, 2017

Why would you post that on the General Photoshop Forum?

create a new fill layer dependant on the colour of the image placed in the file?

What does this mean exactly?

Please consider that a meaningful screenshot could save you some typing.

So if the image is mainly white, create a grey fill layer, or mostly black, create a white fill layer?

The script could evaluate the Histogram of a file or layer, depending how exactly you define »white« and »black« in this context it may be better to create a copy in Lab Colour Mode and evaluate that, though.