Skip to main content
billouparis
Participant
December 17, 2018
Beantwortet

Photoshop Javascript : load selection of opaque pixels but not the transparent pixels.

  • December 17, 2018
  • 3 Antworten
  • 2646 Ansichten

Photoshop Javascript : load selection of opaque pixels but not the transparent pixels of a layer.

I really despair to achieve this in a simple javascript script.

I kinda understood I needed to first load a channel, and then perform a selection from this channel, but I just failed doing this. I don't know how to get the corresponding channel that contains the transparent pixels of the current layer.

The original file is a PNG, it has a single layer.

There is no alpha channel, only R, G and B, although the image has transparent areas.

When I go to select, load Selection, Photoshop suggests by default a channel called layer_name+" Transparency",

therefore I tried something like:

doc.selection.load(doc.channels[layer_name + "Transparency"], SelectionType.EXTEND);

But this just failed.

I think I don't understand the way I am supposed to work with selections and channels

Thanks for any help!

Bill

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von Kukurykus

sTT = stringIDToTypeID;

(ref1 = new ActionReference()).putProperty(c = sTT('channel'), sTT('selection'));

(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);

(ref2 = new ActionReference()).putEnumerated(c, c, sTT('transparencyEnum'))

dsc.putReference(sTT('to'), ref2), executeAction(sTT('set'), dsc);

3 Antworten

JJMack
Community Expert
Community Expert
December 17, 2018

A Selection includes feathering It may well not a B/W cutout there the gray area. Its a grayscale channel

JJMack
Kukurykus
KukurykusAntwort
Legend
December 17, 2018

sTT = stringIDToTypeID;

(ref1 = new ActionReference()).putProperty(c = sTT('channel'), sTT('selection'));

(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);

(ref2 = new ActionReference()).putEnumerated(c, c, sTT('transparencyEnum'))

dsc.putReference(sTT('to'), ref2), executeAction(sTT('set'), dsc);

billouparis
Participant
December 18, 2018

This seems to be working.

Can you tell me what it does exactly, and how you came up with this solution?

Also I would like to get the coodinates of the bounding box around this selection, can I easily find them?

Can I associate this selection to a selection object in javascript?

Thank you!

Bill

billouparis
Participant
December 18, 2018

I found out what I needed

Thank you all!

Bill

Chuck Uebele
Community Expert
Community Expert
December 17, 2018

Can you load the selection by ctrl/cmd clicking on the layer's thumbnail in the layer panel?

billouparis
Participant
December 18, 2018

Hello Chuck,

yes I can.