Skip to main content
Participating Frequently
July 17, 2017
Question

User to select fill layer colour

  • July 17, 2017
  • 2 replies
  • 782 views

I currently have a fill layer function that creates a while layer.. simple

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

    }

Is there a way for the user to select a colour instead of hard coding it? Giving them the option of black or white?

For example if the user was to use a logo as below with a white background it would not look so good. So it would be good to give them the option of a different colour for these situations

This topic has been closed for replies.

2 replies

Inspiring
August 12, 2017

perhaps this function helps:

#target photoshop

function runColorPicker() {

  defColor = app.foregroundColor

  try {

  var bytes;

  var rgb = app.foregroundColor.rgb;

  bytes = (rgb.red << 16) + (rgb.green << 8) + rgb.blue;

  bytes = $.colorPicker(bytes);

  if (bytes != -1) {

  var c = new SolidColor();

  c.rgb.red = (bytes >> 16);

  c.rgb.green = (bytes >> 8) & 0xFF;

  c.rgb.blue = bytes & 0xFF;

  }

  } catch (e) {alert(e)}

  return c;

}

// call PS ColorPicker

var color1 = runColorPicker();

// show result

alert(color1.rgb.red + ' ' + color1.rgb.green + ' ' + color1.rgb.blue)

Chuck Uebele
Community Expert
Community Expert
July 18, 2017

Do you want only black or white - no other colors or shades of gray? If so, you can create a simple UI with radio buttons for them to select either black or white.