Photoshop Gradients File Format

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

Mikaeru

Photoshop Gradients File Format

Post by Mikaeru »

A document describing the Photoshop Gradients File Format is now available from the documentation section of my site.

The sample script Parse Gradients File (for Photoshop CS3 or later) shows how to make use of this information.

Please let me know if you have any comments, corrections or suggestions.

--Mikaeru

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mikaeru

Photoshop Gradients File Format

Post by Mikaeru »

The "Photoshop Gradients File Format" document (v1.6) is now available in both HTML and PDF versions from the documentation section of my site.

--Mikaeru
matterGoal

Photoshop Gradients File Format

Post by matterGoal »

Hi Mikaeru!
I'm really curious to know how you managed the Gradient object! I can't find anything related with Gradient in the Photoshop SDK documentation.
How can you create a grd file?!

Thank you for your time!
Mikaeru

Photoshop Gradients File Format

Post by Mikaeru »

matterGoal wrote:I'm really curious to know how you managed the Gradient object! I can't find anything related with Gradient in the Photoshop SDK documentation.
Using my automation plug-ins JSON Event Listener and JSON Property Getter, part of the JSON Action Toolbox, I was able to isolate and document the format of individual gradient objects, by comparing field names and values with parameters interactively set in the Gradient Editor Dialog. This led me to define a Gradient Object Simplified Format which is more compact and convenient to manipulate.

As for the Photoshop Gradients File Format itself, I had no special need to parse .grd files at that time, but since I noticed that they were made of a simple header followed by a serialized action descriptor (which can be easily decoded by the ActionDescriptor.fromStream method), I thought it was a good opportunity to write a document describing the file format, using the information already gathered for individual gradients.

--Mikaeru
Mikaeru

Photoshop Gradients File Format

Post by Mikaeru »

matterGoal wrote:How can you create a grd file?!
I quickly wrote a simple script named create-gradients-file-example.js (for Photoshop CS2 or later) which should put you on the right track: it will create on the Desktop a custom gradients file containing four different gradients. It has been successfuly tested in Photoshop CS4 on Mac OS X, but should be platform-agnostic.

It makes use of my JSON Action Manager scripting library and takes advantage of the Gradient Object Simplified Format.

HTH,

--Mikaeru
Mikaeru

Photoshop Gradients File Format

Post by Mikaeru »

FYI, I've just released a new sample script called Generate Gradients File (for Photoshop CS3 or later), used to generate a gradients file (.grd) from a JSON text file consisting of an array of gradient objects in Gradient Object Simplified Format.

Just as a reminder, the sample script Parse Gradients File performs the reverse operation.

--Mikaeru
Mike Hale

Photoshop Gradients File Format

Post by Mike Hale »

Mikaeru, you have done some impressive work.

Have or do you plan on doing anything with custom shapes? Specifically I have tried to extract the path info. I think I can see where it is stored. But several attempts I have made to understand the structure of that data has failed.
Mikaeru

Photoshop Gradients File Format

Post by Mikaeru »

Mike Hale wrote:Mikaeru, you have done some impressive work.

Have or do you plan on doing anything with custom shapes? Specifically I have tried to extract the path info. I think I can see where it is stored. But several attempts I have made to understand the structure of that data has failed.
Thanks Mike.

Yes, deciphering the format of a custom shapes file has been on my to-do list for quite some time now...

I think that part of the format is related to the Path resource format described in the document Adobe Photoshop File Formats Specification and is possibly similar (or identical?) to what is used in the Photoshop SDK to write an export plugin using the getproperties callback to extract a path from the current document, and also to write a selection plugin based on a path.

If you have access to an old version of the Photoshop SDK (6 for instance), you may want to have a look a two sample plug-in projects:
- the export module PathsToPostScript, especially the file PathsToPostScript.cpp,
- the selection module Shape: especially the file shape.r.

In the meanwhile, I'll try to have a better understanding of the C++ code of PathsToPostScript and see if porting part of it in JavaScript can be easily done or not...
Mike Hale

Photoshop Gradients File Format

Post by Mike Hale »

Thanks for the reply. I did look at the Photoshop File Spec. From what I can tell the path is stored differently in a custom shape file than it is in the psd file. Or at least I wasn't able to extract the info I need that way.

All the SDK from version 6 to CS6 can be downloaded from Adobe except 7 for some reason. So having access to the SDK is not a problem. But I don't know C++ and I can't follow what is going on in the examples.

There are two thing I would like to do where I need to know the original path's aspect ratio.

1. Create a path or vector mask from a custom shape without distorting the original shape. I can do that in the GUI by holding down the shift key. And I can use Action Manger to create a path but it distorts because I can't determine the correct aspect ration to set the bounding box.

2. Correct for the distortion caused by the shape blur filter. That filter makes the shape more square shaped than the original.

I can find the bounding box info in the custom shape file( thanks to Xbytor ). But it seems that it is only accurate when the shape was made from a path created in Photoshop. If the path was created with some other vector app like Illustrator the bounding box info can be off. Or I could have not done enough testing and it can also be off with paths created in Photoshop but I spent a good bit of time on this.

I was hoping that if I could extract the original path info from the custom shape, I would then determine the correct aspect ratio or just use the path itself.

Mike
Mikaeru

Photoshop Gradients File Format

Post by Mikaeru »

I've just released a new document called Photoshop Custom Shapes File Format (beta version) which is an attempt at deciphering the format of a custom shapes file. There are still a few unknown fields, but it shouldn't be a problem for the time being...

I also quickly wrote a basic script called Parse Custom Shapes File (beta version) making use of the information contained in the document.

Mike Hale wrote:I was hoping that if I could extract the original path info from the custom shape, I would then determine the correct aspect ratio or just use the path itself.
From what I do understand after studying the file format, it probably won't be possible to extract the correct aspect ratio from a custom shapes file because the bounding-box it contains is related to the minimum and maximum coordinates of the *anchor* and *control* points of the path, whereas the bounding-box used at the user-interface level encloses the *outline* of the shape.

Fortunately, it is possible to extract the path itself. I'm going to work on that from now on.

HTH,

--Mikaeru