在 photoshop 脚本中,您如何循环每个选择并在每次迭代期间应用渐变效果?

In photoshop scripting how do you loop each selection and apply a gradient effect during each iteration?

请忽略蓝线。基本上,我想使用 select > 颜色范围或魔术棒制作一些 select 离子,并且对于每个 selected 补丁,我想在补丁的中心应用一些渐变。

伪代码为:

select current active layer

apply color range or magic wand selection

for each sub selection in main selection:

    do: 
        calculate the center coordinate of the current sub-selection area
        apply a custom gradient using the coordinate as the starting point

我不确定这是否可行,因为我不知道颜色范围或魔法是否需要 selection 包含 "sub-selections"。子 select 离子是指上图中的每个单独的补丁。

没有子选择,但是您可以将选择转换为 Path 对象,每个单独的路径都可以用于迭代。根据您的选择(颜色范围可能会给出半透明选择),您可能希望先将当前选择保存为单独的通道并修改选择以使其 100% 不透明。

要计算中心,我想这样的事情应该可行:Find centerpoint of polygon in JavaScript 因为你可以获得每个子路径的控制点的所有坐标。

然后您需要一个接一个地创建选择岛,这样渐变就不会相互影响。为此,您可以使用路径点作为套索选择的点,然后将这些套索选择与原始选择通道相交以重新获得丢失的透明度。