Skip to main content
Participant
May 14, 2009
Answered

How to change Image color like Channel mixer

  • May 14, 2009
  • 1 reply
  • 2361 views

Hello everybody

I have this problem can anyone help me:

I want to change Channel mixer color,

for example, change original Image color to B&W.

My code:

docRef.channels[0].color.rgb.red = 30;

docRef.channels[0].color.rgb.green = 59;

docRef.channels[0].color.rgb.blue = 11;

docRef.channels[1].color.rgb.red = 30;

docRef.channels[1].color.rgb.green = 59;

docRef.channels[1].color.rgb.blue = 11;

docRef.channels[2].color.rgb.red = 30;

docRef.channels[2].color.rgb.green = 59;

docRef.channels[2].color.rgb.blue = 11;

But not working in scripting, seems a mistake.

How should I correct this code? Thank you for your help.

This topic has been closed for replies.
Correct answer Michael_L_Hale

Hi , Muppet Mark.

you can try this code in your js

var doc=app.activeDocument;


doc.layers[0].mixChannels([[30,59,11,0],[30,59,11,0],[30,59,11,0]],false);

                                       

this is change color to B&W.


Your code only converts the layer to B&W because the 3 arrays have the same value. Had you used doc.layers[0].mixChannels([[60,30,10,0],[30,10,60,0],[10,60,30,0]],false); the layer would still have some color.

doc.layers[0].mixChannels([[30,59,11,0]],true); would be a clearer way to do what your code does. Note the monochrome argument is set to true.

1 reply

Paul Riggott
Inspiring
May 14, 2009

This is what I use...

BlackWhite(27,36,37);

function function BlackWhite(Red,Green,Blue) {
  function cTID(s) { return app.charIDToTypeID(s); };
  function sTID(s) { return app.stringIDToTypeID(s); };

    var desc2 = new ActionDescriptor();
    desc2.putEnumerated( sTID('presetKind'), sTID('presetKindType'), sTID('presetKindCustom') );
    desc2.putBoolean( cTID('Mnch'), true );
        var desc3 = new ActionDescriptor();
        desc3.putUnitDouble( cTID('Rd  '), cTID('#Prc'), Red );
        desc3.putUnitDouble( cTID('Grn '), cTID('#Prc'), Green );
        desc3.putUnitDouble( cTID('Bl  '), cTID('#Prc'), Blue );
    desc2.putObject( cTID('Gry '), cTID('ChMx'), desc3 );
    executeAction( cTID('ChnM'), desc2, DialogModes.NO );
};

Participant
May 14, 2009

Thanks Paul Riggott.

You can solve the B&W color, I think 'docRef.backgroundLayer.desaturate()'  is a simpler method.

But I had 9 parameters, each channel has 3 parameters, each parameter's value maybe different, How can I do ?

Thank you again for your information on my question.

Inspiring
May 14, 2009

desaturate may be simple but it doesn't work like channel mixer. The function Paul posted does.

I am not sure what you are trying to do but a channel can not have 3 values unless it is a spot color channel. The component channels do not have a color property.