Detect alpha channel

Does anyone know if there’s any good way to tell which channels are in a document? Looking to create an alpha channel if there isn’t one already.

Thanks

You can get a channel via

const channel = await require("photoshop").action.batchPlay(
[
   {
      "_obj": "get",
      "_target": {
          "_enum": "channel",
          "_ref": "channel",
          "_value": *channelType*
        },
   }
],{
   "synchronousExecution": true,
});

where channelType can be one of
composite, mask, filterMask, transparencyEnum, RGB, red, green, blue, CMYK, black, cyan, magenta, yellow, lab, lightness, a, b, gray, monotone, duotone, tritone, quadtone

If the channel doesn’t exist the returned descriptor will have a message property saying that the command “get” is not available.

But I think the channels depend on the currently active layer, don’t they?

Without DOM you gonna have very difficult and messy work. I already did something like that. You need to know color space, then its enums. Also, you need to get number of channels in document but I think this might be affected by selected layers because layer masks can also appear here.

We urgently need a DOM here for the basics so we could extend it easily.

This is how Alchemist lists channels

But it won’t tell you channel type/kind.

The best try could be:

  • select none layer
  • get document color space
  • compare number of channels in document with color space
  • if number is higher they you likely have alpha channel

Thanks for both of your help, was able to achieve what I need to at this point by getting the channel count with get.

1 Like