Parse Gradients File

Description

“Parse Gradients File” is a gradients utility script using the JSON Action Manager scripting library.

This stand-alone script written in JavaScript is used to parse a Photoshop gradients file (.grd) into a JSON text file containing a JSON array of gradient objects, each one in Gradient Object Simplified Format, as expected by the function jamHelpers.toGradientObject.

From a technical point of view, it shows how to take advantage of the method ActionDescriptor.fromStream to decode a flattened (serialized) version of an ActionDescriptor object saved in a file.

The utility script Generate Gradients File performs the reverse operation, i.e., converts a JSON text file, containing a JSON array of gradient objects in Gradient Object Simplified Format, into a Photoshop gradients file (.grd).

Please refer to the Photoshop Gradients File Format document for detailed information about the structure of a gradients file.

Example of parsed gradients file (Metals.json):

[
    {
        "name": "$$$/Presets/Gradients/Metals_grd/Brass=Brass",
        "gradientForm": "customStops",
        "interpolation": 4096,
        "colors":
        [
            {
                "color":
                {
                    "red": 235,
                    "green": 219.996108949416,
                    "blue": 35.0038910505837
                },
                "type": "userStop",
                "location": 0,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 255,
                    "green": 251.996108949416,
                    "blue": 193.996108949416
                },
                "type": "userStop",
                "location": 1024,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 233,
                    "green": 217,
                    "blue": 28
                },
                "type": "userStop",
                "location": 2048,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 255,
                    "green": 251.996108949416,
                    "blue": 199.996108949416
                },
                "type": "userStop",
                "location": 3072,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 233.996108949416,
                    "green": 215,
                    "blue": 32
                },
                "type": "userStop",
                "location": 4096,
                "midpoint": 50
            }
        ],
        "transparency":
        [
            {
                "opacity": 100,
                "location": 0,
                "midpoint": 50
            },
            {
                "opacity": 100,
                "location": 4096,
                "midpoint": 50
            }
        ]
    },
    {
        "name": "$$$/Presets/Gradients/Metals_grd/Gold=Gold",
        "gradientForm": "customStops",
        "interpolation": 4096,
        "colors":
        [
            {
                "color":
                {
                    "red": 255,
                    "green": 203.996108949416,
                    "blue": 60
                },
                "type": "userStop",
                "location": 0,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 255,
                    "green": 245.996108949416,
                    "blue": 223.996108949416
                },
                "type": "userStop",
                "location": 1024,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 255,
                    "green": 203,
                    "blue": 56
                },
                "type": "userStop",
                "location": 2048,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 255,
                    "green": 247,
                    "blue": 229
                },
                "type": "userStop",
                "location": 3072,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 255,
                    "green": 203,
                    "blue": 56
                },
                "type": "userStop",
                "location": 4096,
                "midpoint": 50
            }
        ],
        "transparency":
        [
            {
                "opacity": 100,
                "location": 0,
                "midpoint": 50
            },
            {
                "opacity": 100,
                "location": 4096,
                "midpoint": 50
            }
        ]
    },
    {
        "name": "$$$/Presets/Gradients/Metals_grd/Silver=Silver",
        "gradientForm": "customStops",
        "interpolation": 4096,
        "colors":
        [
            {
                "color":
                {
                    "red": 83.0038910505837,
                    "green": 91.0038910505837,
                    "blue": 94
                },
                "type": "userStop",
                "location": 0,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 253.996108949416,
                    "green": 253.996108949416,
                    "blue": 253.996108949416
                },
                "type": "userStop",
                "location": 1024,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 74,
                    "green": 81.0038910505837,
                    "blue": 84
                },
                "type": "userStop",
                "location": 2048,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 253,
                    "green": 253,
                    "blue": 253
                },
                "type": "userStop",
                "location": 3072,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 83.0038910505837,
                    "green": 91.0038910505837,
                    "blue": 94
                },
                "type": "userStop",
                "location": 4096,
                "midpoint": 50
            }
        ],
        "transparency":
        [
            {
                "opacity": 100,
                "location": 0,
                "midpoint": 50
            },
            {
                "opacity": 100,
                "location": 4096,
                "midpoint": 50
            }
        ]
    },
    {
        "name": "$$$/Presets/Gradients/Metals_grd/SteelBar=Steel Bar",
        "gradientForm": "customStops",
        "interpolation": 4096,
        "colors":
        [
            {
                "color":
                {
                    "hue": 0,
                    "saturation": 0,
                    "brightness": 0
                },
                "type": "userStop",
                "location": 0,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 253.996108949416,
                    "green": 253.996108949416,
                    "blue": 253.996108949416
                },
                "type": "userStop",
                "location": 2867,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 1.00389105058366,
                    "green": 1.00389105058366,
                    "blue": 1.00389105058366
                },
                "type": "userStop",
                "location": 4096,
                "midpoint": 50
            }
        ],
        "transparency":
        [
            {
                "opacity": 100,
                "location": 0,
                "midpoint": 50
            },
            {
                "opacity": 100,
                "location": 4096,
                "midpoint": 50
            }
        ]
    },
    {
        "name": "$$$/Presets/Gradients/Metals_grd/SteelBlue=Steel Blue",
        "gradientForm": "customStops",
        "interpolation": 4096,
        "colors":
        [
            {
                "color":
                {
                    "red": 30,
                    "green": 93.0038910505837,
                    "blue": 177.996108949416
                },
                "type": "userStop",
                "location": 0,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 231,
                    "green": 233,
                    "blue": 243.996108949416
                },
                "type": "userStop",
                "location": 1024,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 30,
                    "green": 93.0038910505837,
                    "blue": 177.996108949416
                },
                "type": "userStop",
                "location": 2048,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 233,
                    "green": 235,
                    "blue": 243.996108949416
                },
                "type": "userStop",
                "location": 3072,
                "midpoint": 50
            },
            {
                "color":
                {
                    "red": 30,
                    "green": 93.0038910505837,
                    "blue": 177.996108949416
                },
                "type": "userStop",
                "location": 4096,
                "midpoint": 50
            }
        ],
        "transparency":
        [
            {
                "opacity": 100,
                "location": 0,
                "midpoint": 50
            },
            {
                "opacity": 100,
                "location": 4096,
                "midpoint": 50
            }
        ]
    }
]

Preset Manager Gradients (Metals)

Requirements

This script can be used in Adobe Photoshop CS3 or later. It has been successfully tested in CS4 on Mac OS X, but should be platform agnostic.

Copyright

This Software is copyright © 2011-2015 by Michel MARIANI.

License

This Software is licensed under the GNU General Public License (GPL) v3.

Download

Installation

Download the Zip file and unzip it.

Move the script to the Presets/Scripts folder in the default preset location of the Adobe Photoshop application. On next launch, the script will appear in the File>Automate submenu.

Version History

  • 4.5

    • Used new version 4.4.4 of jamEngine scripting library module.
  • 4.4

    • Used new version 4.4.1 of scripting library modules.
  • 4.3

    • Used new version 4.3 of jamHelpers scripting library module.
  • 4.2

    • Fixed generation of output file name and presets folder name.
    • Simplified test in isGrdFile ().
  • 4.1

    • Used new version 4.0 of scripting library modules.
  • 4.0

    • Used new version of jamEngine scripting library module.
  • 3.9

    • Used new version of scripting library modules.
    • Used new explicit format.
  • 3.8

    • Used new version of scripting library modules.
  • 3.7

    • Modified string of file selection filter for gradients preferences file.
  • 3.6

    • Used new version of scripting library modules.
  • 3.5

    • Improved handling of file extensions.
    • Used updated version of jamUtils.writeJsonFile (), adding ‘TEXT’ Mac OS type to newly created JSON file.
  • 3.4

    • Modified terminology: “save folder” -> “output folder”.
    • Improved prompt messages in open and save dialogs.
  • 3.3

    • Renamed script from “Convert Gradients File” to “Parse Gradients File”.
    • Added the option to automatically open the save folder.
    • Added the option to expand tabs to four spaces.
    • Used new version of scripting library modules.
  • 3.2

    • Modified the file selection filter to allow for the gradients file located in the preferences folder.
  • 3.1

    • Incremented version number to keep in sync with scripting library modules.
  • 3.0

    • Incremented version number to keep in sync with scripting library modules.
  • 2.0

    • Initial release.

Tags: , , , , ,

Comments are closed.