Skip to main content
Participant
March 19, 2019
Answered

How to invert an Alpha Channel in JS

  • March 19, 2019
  • 2 replies
  • 1067 views

Hey Guys and Gal's,

I have a selected channel that I'm looking to invert but I'm not seeing to have any luck.

I've tried the below (Inverting the Red Channel in this case)

  1. app.activeDocument.activeChannels = [app.activeDocument.channels[0]]; 
  2. app.activeDocument.activeLayer.invert(); 
  3. app.activeDocument.activeChannels = [app.activeDocument.channels[0],app.activeDocument.channels[1],app.activeDocument.channels[2]];

I've also tried app.activeDocument.activeChannels.invert(); but also to no avail.

I even tried it in an action and it failed. can anyone direct me to the best way of doing this?

Thanks.

This topic has been closed for replies.
Correct answer Chuck Uebele

var idslct = charIDToTypeID( "slct" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idRd = charIDToTypeID( "Rd  " );

        ref1.putEnumerated( idChnl, idChnl, idRd );

    desc2.putReference( idnull, ref1 );

executeAction( idslct, desc2, DialogModes.NO );

var idInvr = charIDToTypeID( "Invr" );

executeAction( idInvr, undefined, DialogModes.NO );

Or

var doc = activeDocument;

doc.channels.activeChannel= doc.channels[0]

var idInvr = charIDToTypeID( "Invr" );

executeAction( idInvr, undefined, DialogModes.NO );

2 replies

Participating Frequently
March 20, 2019

Bonjour

Forgive me Chuck Uebele?


Diefish

You have a fault on this line (03):
channel s instead of channels
app.activeDocument.channel s [2]];
app.activeDocument.channels [2]] it's better !

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
March 19, 2019

var idslct = charIDToTypeID( "slct" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idRd = charIDToTypeID( "Rd  " );

        ref1.putEnumerated( idChnl, idChnl, idRd );

    desc2.putReference( idnull, ref1 );

executeAction( idslct, desc2, DialogModes.NO );

var idInvr = charIDToTypeID( "Invr" );

executeAction( idInvr, undefined, DialogModes.NO );

Or

var doc = activeDocument;

doc.channels.activeChannel= doc.channels[0]

var idInvr = charIDToTypeID( "Invr" );

executeAction( idInvr, undefined, DialogModes.NO );