Copy link to clipboard
Copied
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
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);
Copy link to clipboard
Copied
Can you load the selection by ctrl/cmd clicking on the layer's thumbnail in the layer panel?
Copy link to clipboard
Copied
Hello Chuck,
yes I can.
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I found out what I needed
Thank you all!
Bill
Copy link to clipboard
Copied
You can use ScriptListener to get similar code.
Bounding box coordinates you're taking using:
activeDocument.selection.bounds
I don't know what you mean by last question?
Copy link to clipboard
Copied
A Selection includes feathering It may well not a B/W cutout there the gray area. Its a grayscale channel
Find more inspiration, events, and resources on the new Adobe Community
Explore Now