Page 1 of 1

Reading Group Layers in PSD files

Posted: 2009-07-01T08:11:00-07:00
by IonSwitz
I was wondering if there is currently any work being done to support groups in PSD files?

Something that would be of immense value to me would be to be able to use "convert" from the command line and, instead of getting all the layers as separate PNG files, I would like to be able to get all the Layer Groups from the PSD file rendered into separate files.

It is my understanding that there is no such support at the moment. I am willing to spend some time developing the necessary code, if the community knows more about the PSD file format than I do. :)

I've compiled the ImageMagick code base and I'm stepping through the psd.c file while loading a large PSD file with many groups, each containing a variable number of layers. It seems to me that layer_info entries with a page width or a page height of 0 is removed as the current implementation ignores them. (Added by "palf" )

This could instead be used as "marker points" for an algorithm that splits up the layer_info into layer_group_info superstructures.

This type of segmentation could allow the extension of the "convert" command line command with another set of brackets.

Basically, it would be real nice to be able to write:

convert foo.psd[1-4][1-10] bar.png

which should be read as "for the first 4 groups in foo.psd, extract layers 1-10, and composite the ten layers into bar-group-1.png, bar-group-2.png, bar-group-3.png and bar-group-4.png" , or similar.

The syntax might be totally foolish, but I hope I'm being clear of what I want to get done. :)

Anyway, if anyone thinks this is worth the time, let me know. Also, tell me if this is a fool's errand. From what I've gathered, the PSD file format is one hairy beast, and not very programmer friendly. So, all comments on this is very appreciated.

Re: Reading Group Layers in PSD files

Posted: 2009-07-01T09:07:23-07:00
by magick
The image infastructure requires that images are stored as doubly linked lists. We could support image groups by adding a metatag group name. Dealing with groups then would require that the image list is traversed looking for images that have similar group names. The tough part is defining a syntax for dealing with groups such as you suggested for reading an image. In addition we would need a method to add a new or delete a group or add or delete images from a particular group. We could even deal with a heirarchy of groups using names spaces, e.g. group-1, group-1:students, etc.

To get started, download the latest psd.c module from Subversion and add a group property that distinquished the image and group. Post your patch here.

Re: Reading Group Layers in PSD files

Posted: 2009-07-01T09:19:43-07:00
by IonSwitz
Thank you for your response.

However, I believe I ran into a brick wall by not diving deep enough into the problem pool. Each group can contain more groups. It would rapidly become quite nasty to generate such a tree structure with metadata, I believe, without changing more in the global Image struct. And, well, by changing the Image struct, one would change the entire world of ImageMagick for a fix that only pertains to PSD files. It sounds fairly harsh.

Also, so far I haven't been able to find a way to detect if an Image_Layer with a page width of 0 is the end of the current group layer or the start of a new, nested, layer group. This makes building the hierarchy even harder.

There's a lot of unknown (at least to me) bytes at the end of the PSD data stream for each Image_Layer, maybe the solution to this problem can be found in that chunk of data, but I really have no idea what lies hidden in that blob.

In short: It seems fairly hard to develop this feature. :(

Re: Reading Group Layers in PSD files

Posted: 2009-07-02T05:53:31-07:00
by jn0101
Hi IonSwitz

This post about PSD might be of interest you too:
viewtopic.php?f=2&t=14103

I am hoping I get some time to dive into psd.c by end August.

Perhaps we could do some co-development to fix some PSD file reading/writing bugs?

Yours,
Jacob Nordfalk

Re: Reading Group Layers in PSD files

Posted: 2011-05-21T03:20:33-07:00
by MikeOwen
Hi,
2 years later!
Has anyone added support or in the process of adding PSD group name support to Image Magick?!
Please!
Thanks,
Mike

Re: Reading Group Layers in PSD files

Posted: 2012-01-12T02:31:03-07:00
by jn0101
Sorry, no I didnt get the time allocated.

It seems that newer IM has slightly improved support, according to the changelog.