Skip to content

Adjustments

src.helpers.adjustments.create_vibrant_saturation(vibrancy: int, saturation: int) -> None

Experimental scoot action to add vibrancy and saturation.

Parameters:

Name Type Description Default
vibrancy int

Vibrancy level integer

required
saturation int

Saturation level integer

required
Source code in src\helpers\adjustments.py
26
27
28
29
30
31
32
33
34
35
36
37
def create_vibrant_saturation(vibrancy: int, saturation: int) -> None:
    """Experimental scoot action to add vibrancy and saturation.

    Args:
        vibrancy: Vibrancy level integer
        saturation: Saturation level integer
    """
    # dialogMode (Have dialog popup?)
    desc232 = ActionDescriptor()
    desc232.putInteger(sID("vibrance"), vibrancy)
    desc232.putInteger(sID("saturation"), saturation)
    APP.executeAction(sID("vibrance"), desc232, NO_DIALOG)

src.helpers.adjustments.create_color_layer(color: Union[list[int], SolidColor, str], layer: Union[ArtLayer, LayerSet, None], docref: Optional[Document] = None, **kwargs) -> ArtLayer

Create a solid color adjustment layer.

Parameters:

Name Type Description Default
color list[int] | SolidColor | str

Color to use for the layer.

required
layer ArtLayer | LayerSet | None

ArtLayer or LayerSet to make active, if provided.

required
docref Document | None

Reference Document, use active if not provided.

None

Returns:

Type Description
ArtLayer

The new solid color adjustment layer.

Source code in src\helpers\adjustments.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def create_color_layer(
    color: Union[list[int], SolidColor, str],
    layer: Union[ArtLayer, LayerSet, None],
    docref: Optional[Document] = None,
    **kwargs
) -> ArtLayer:
    """Create a solid color adjustment layer.

    Args:
        color: Color to use for the layer.
        layer: ArtLayer or LayerSet to make active, if provided.
        docref: Reference Document, use active if not provided.

    Keyword Args:
        clipped (bool): Whether to apply as a clipping mask to the nearest layer, defaults to True.
        blend_mode (BlendMode): Optional blend mode to apply to the new layer.

    Returns:
        The new solid color adjustment layer.
    """
    docref = docref or APP.activeDocument
    if layer:
        docref.activeLayer = layer
    desc1 = ActionDescriptor()
    ref1 = ActionReference()
    desc2 = ActionDescriptor()
    desc3 = ActionDescriptor()
    ref1.putClass(sID("contentLayer"))
    desc1.putReference(sID("target"), ref1)
    desc2.putBoolean(sID("group"), kwargs.get('clipped', True))
    desc2.putEnumerated(sID("color"), sID("color"), sID("blue"))
    apply_color(desc3, color)
    desc2.putObject(sID("type"), sID("solidColorLayer"), desc3)
    desc1.putObject(sID("using"), sID("contentLayer"), desc2)
    APP.executeAction(sID("make"), desc1, NO_DIALOG)
    layer = docref.activeLayer
    if 'blend_mode' in kwargs:
        layer.blendMode = kwargs['blend_mode']
    return layer

src.helpers.adjustments.create_gradient_layer(colors: list[dict], layer: Union[ArtLayer, LayerSet, None], docref: Optional[Document] = None, **kwargs) -> ArtLayer

Create a gradient adjustment layer.

Parameters:

Name Type Description Default
colors list[dict]

List of gradient color dicts.

required
layer ArtLayer | LayerSet | None

ArtLayer or LayerSet to make active, if provided.

required
docref Document | None

Reference Document, use active if not provided.

None

Returns:

Type Description
ArtLayer

The new gradient adjustment layer.

Source code in src\helpers\adjustments.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def create_gradient_layer(
    colors: list[dict],
    layer: Union[ArtLayer, LayerSet, None],
    docref: Optional[Document] = None,
    **kwargs
) -> ArtLayer:
    """Create a gradient adjustment layer.

    Args:
        colors: List of gradient color dicts.
        layer: ArtLayer or LayerSet to make active, if provided.
        docref: Reference Document, use active if not provided.

    Keyword Args:
        clipped (bool): Whether to apply as a clipping mask to the nearest layer, defaults to True.
        rotation (Union[int, float]): Rotation to apply to the gradient, defaults to 90.
        scale (Union[int, float]): Scale to apply to the gradient, defaults to 100.
        blend_mode (BlendMode): Optional blend mode to apply to the new layer.

    Returns:
        The new gradient adjustment layer.
    """
    docref = docref or APP.activeDocument
    if layer:
        docref.activeLayer = layer
    desc1 = ActionDescriptor()
    ref1 = ActionReference()
    desc2 = ActionDescriptor()
    desc3 = ActionDescriptor()
    desc4 = ActionDescriptor()
    color_list = ActionList()
    list2 = ActionList()
    desc9 = ActionDescriptor()
    desc10 = ActionDescriptor()
    ref1.putClass(sID("contentLayer"))
    desc1.putReference(sID("target"),  ref1)
    desc2.putBoolean(sID("group"), kwargs.get('clipped', True))
    desc3.putEnumerated(
        sID("gradientsInterpolationMethod"),
        sID("gradientInterpolationMethodType"),
        sID("perceptual"))
    desc3.putUnitDouble(sID("angle"), sID("angleUnit"), kwargs.get('rotation', 0))
    desc3.putEnumerated(sID("type"), sID("gradientType"), sID("linear"))
    desc3.putUnitDouble(sID("scale"), sID("percentUnit"), kwargs.get('scale', 100))
    desc4.putEnumerated(sID("gradientForm"), sID("gradientForm"), sID("customStops"))
    desc4.putDouble(sID("interfaceIconFrameDimmed"),  4096)
    for c in colors:
        add_color_to_gradient(
            color_list,
            get_color(c.get('color', rgb_black())),
            int(c.get('location', 0)),
            int(c.get('midpoint', 50))
        )
    desc4.putList(sID("colors"),  color_list)
    desc9.putUnitDouble(sID("opacity"), sID("percentUnit"),  100)
    desc9.putInteger(sID("location"),  0)
    desc9.putInteger(sID("midpoint"),  50)
    list2.putObject(sID("transferSpec"),  desc9)
    desc10.putUnitDouble(sID("opacity"), sID("percentUnit"),  100)
    desc10.putInteger(sID("location"),  4096)
    desc10.putInteger(sID("midpoint"),  50)
    list2.putObject(sID("transferSpec"),  desc10)
    desc4.putList(sID("transparency"),  list2)
    desc3.putObject(sID("gradient"), sID("gradientClassEvent"),  desc4)
    desc2.putObject(sID("type"), sID("gradientLayer"),  desc3)
    desc1.putObject(sID("using"), sID("contentLayer"),  desc2)
    APP.executeAction(sID("make"), desc1,  NO_DIALOG)
    layer = docref.activeLayer
    if 'blend_mode' in kwargs:
        layer.blendMode = kwargs['blend_mode']
    return layer