4
4
Fork 0
This repository has been archived on 2025-01-20. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
json-photoshop-scripting/JSON-Simplified-Formats/Gradient-Object-Simplified-Format
2024-02-24 13:35:32 +01:00
..
images First commit 2018-04-15 16:41:40 +02:00
README.md Fixed relative links in README.md files 2024-02-24 13:35:32 +01:00

Gradient Object Simplified Format

  • Input format of jamHelpers.toGradientObject.
  • Output format of jamHelpers.fromGradientObject.

Used by the following utility scripts:

Explicit format

Solid gradient

Defined as a JSON object:

{
    "name": name,
    "gradientForm": "customStops",
    "interpolation": interpolation,
    "colors": colors,
    "transparency": transparency
}

name : string (or null in input)
interpolation : number (0 to 4096)
colors : JSON array of JSON objects in Color stop format
transparency: [optional in input] JSON array of JSON objects in Transparency stop format

Color stop

{
    "location": location,
    "midpoint": midpoint,
    "type": type,
    "color": color
}

location : number (0 to 4096)
midpoint : number (percentage; 0% to 100%)
type : string (among "foregroundColor", "backgroundColor", "userStop")
color : [optional, only if type is "userStop"] JSON object in Color Object Simplified Format

Transparency stop

{
    "location": location,
    "midpoint": midpoint,
    "opacity": opacity
}

location : number (0 to 4096)
midpoint : number (percentage; 0% to 100%)
opacity : number (percentage; 0% to 100%)

Noise gradient

Defined as a JSON object:

{
    "name": name,
    "gradientForm": "colorNoise",
    "randomSeed": randomSeed,
    "showTransparency": showTransparency,
    "vectorColor": vectorColor,
    "smoothness": smoothness,
    "colorSpace": colorSpace,
    "minimum": minimum,
    "maximum": maximum
}

name : string (or null in input)
randomSeed : number
showTransparency : boolean
vectorColor : boolean
smoothness : number (0 to 4096)
colorSpace : string ("RGBColor" or "HSBColorEnum" or "labColor")
minimum : JSON array of four numbers, i.e., three color components (0 to 100) + transparency (0)
maximum : JSON array of four numbers, i.e., three color components (0 to 100) + transparency (100)

Minimal format

Solid gradient

Defined as a five-element JSON array:

[
    name,
    "customStops",
    interpolation,
    colors,
    transparency
]

name : string (or null in input)
interpolation : number (0 to 4096)
colors : JSON array of Color stops
transparency : [optional in input] JSON array of Transparency stops

A Color stop is defined as a JSON array of three or four elements:

type value
"foregroundColor"
"backgroundColor"
[ location, midpoint, type ]
"userStop" [ location, midpoint, type, color ]

location : number (0 to 4096)
midpoint : number (percentage; 0% to 100%)
type : string (among "foregroundColor", "backgroundColor", "userStop")
color : [optional, only if type is "userStop"] JSON array in Color Object Simplified Format

A Transparency stop is defined as a JSON array of three elements:

[ location, midpoint, opacity ]

location : number (0 to 4096)
midpoint : number (percentage; 0% to 100%)
opacity : number (percentage; 0% to 100%)

Noise gradient

Defined as a nine-element JSON array:

[
    name,
    "colorNoise",
    randomSeed,
    showTransparency,
    vectorColor,
    smoothness,
    colorSpace,
    minimum,
    maximum
]

name : string (or null in input)
randomSeed : number
showTransparency : boolean
vectorColor : boolean
smoothness : number (0 to 4096)
colorSpace : string ("RGBColor" or "HSBColorEnum" or "labColor")
minimum : JSON array of four numbers, i.e., three color components (0 to 100) + transparency (0)
maximum : JSON array of four numbers, i.e., three color components (0 to 100) + transparency (100)

Notes

  • The two different kinds of gradients (and their corresponding format) are automatically discriminated based on the value of the element gradientForm: either "customStops" or "colorNoise".

  • interpolation, location and smoothness have values between 0 and 4096 whereas they are expressed as percentages (0% to 100%) in the gradient editor dialog.

Examples

{
    "name": "Foreground to Background",
    "gradientForm": "customStops",
    "interpolation": 4096,
    "colors":
    [
        { "location": 0, "midpoint": 50, "type": "foregroundColor" },
        { "location": 4096, "midpoint": 50, "type": "backgroundColor" }
    ],
    "transparency":
    [
        { "location": 0, "midpoint": 50, "opacity": 100 },
        { "location": 4096, "midpoint": 50, "opacity": 100 }
    ]
}
[
    "Foreground to Background",
    "customStops",
    4096,
    [
        [ 0, 50, "foregroundColor" ],
        [ 4096, 50, "backgroundColor" ]
    ],
    [
        [ 0, 50, 100 ],
        [ 4096, 50, 100 ]
    ]
]

Foreground to Background Gradient Editor Dialog

{
    "name": "Blue, Red, Yellow",
    "gradientForm": "customStops",
    "interpolation": 4096,
    "colors":
    [
        {
            "location": 0, "midpoint": 50, "type": "userStop",
            "color": { "hue": 240, "saturation": 100, "brightness": 100 }
        },
        {
            "location": 2048, "midpoint": 50, "type": "userStop",
            "color": { "hue": 0, "saturation": 100, "brightness": 100 }
        },
        {
            "location": 4096, "midpoint": 50, "type": "userStop",
            "color": { "hue": 60, "saturation": 100, "brightness": 100 }
        }
    ],
    "transparency":
    [
        { "location": 0, "midpoint": 50, "opacity": 100 },
        { "location": 4096, "midpoint": 50, "opacity": 100 }
    ]
}
[
    "Blue, Red, Yellow",
    "customStops",
    4096,
    [
        [ 0, 50, "userStop", [ "HSBColorClass", [ 240, 100, 100 ] ] ],
        [ 2048, 50, "userStop", [ "HSBColorClass", [ 0, 100, 100 ] ] ],
        [ 4096, 50, "userStop", [ "HSBColorClass", [ 60, 100, 100 ] ] ]
    ],
    [
        [ 0, 50, 100 ],
        [ 4096, 50, 100 ]
    ]
]

Blue Red Yellow Gradient Editor Dialog

{
    "name": "Color Noise",
    "gradientForm": "colorNoise",
    "randomSeed": 345807450,
    "showTransparency": false,
    "vectorColor": true,
    "smoothness": 1024,
    "colorSpace": "RGBColor",
    "minimum": [ 0, 18, 25, 0 ],
    "maximum": [ 100, 60, 73, 100 ]
}
[
    "Color Noise",
    "colorNoise",
    345807450,
    false,
    true,
    1024,
    "RGBColor",
    [ 0, 18, 25, 0 ],
    [ 100, 60, 73, 100 ]
]

Color Noise Gradient Editor Dialog