-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFeather-Scaler.jsx
More file actions
80 lines (61 loc) · 2.47 KB
/
Feather-Scaler.jsx
File metadata and controls
80 lines (61 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
79
80
#target photoshop
// DISCLAIMER: This script is written by AI
function InitializeScript()
{
if (!documents.length)
return;
var doc = activeDocument;
// Input dialog
var scaleFactor = prompt("Enter scaling factor for Vector Feather:\n(Example: 2 to double, 0.5 to halve)", "2");
if (scaleFactor === null) // Exit if Cancel is pressed
return;
scaleFactor = parseFloat(scaleFactor.replace(",", ".")); // Handle both dot and comma
if (isNaN(scaleFactor) || scaleFactor <= 0)
{
alert("Please enter a valid number greater than 0.");
return;
}
function processLayers(layers)
{
for (var i = 0; i < layers.length; i++)
{
var layer = layers[i];
if (layer.typename === "LayerSet")
processLayers(layer.layers); // Recursive search through groups
else
scaleFeather(layer);
}
}
function scaleFeather(layer)
{
try
{
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("vectorMaskFeather"));
ref.putIdentifier(charIDToTypeID("Lyr "), layer.id);
var desc = executeActionGet(ref);
if (desc.hasKey(stringIDToTypeID("vectorMaskFeather")))
{
var currentFeather = desc.getUnitDoubleValue(stringIDToTypeID("vectorMaskFeather"));
if (currentFeather > 0)
{
var setDesc = new ActionDescriptor();
var layerRef = new ActionReference();
layerRef.putIdentifier(charIDToTypeID("Lyr "), layer.id);
setDesc.putReference(charIDToTypeID("null"), layerRef);
var featherDesc = new ActionDescriptor();
featherDesc.putUnitDouble(stringIDToTypeID("vectorMaskFeather"), charIDToTypeID("#Pxl"), currentFeather * scaleFactor);
setDesc.putObject(charIDToTypeID("T "), charIDToTypeID("Lyr "), featherDesc);
executeAction(charIDToTypeID("setd"), setDesc, DialogModes.NO);
}
}
}
catch (e)
{
// Skip layers without vector masks
}
}
// Wrap everything in a single history state
doc.suspendHistory("Scale Vector Feather by " + scaleFactor, "processLayers(doc.layers)");
}
InitializeScript();