Extract layers from PSD with ImageMagick, preserving layout

Thom picture Thom · Jul 6, 2011 · Viewed 16.6k times · Source

I'm using ImageMagick to extract layers from a PSD, and it gets them all out fine with:

convert image.psd image-%d.png

But the resulting PNG images are of varying dimensions, depending on the actual contents of the layer. What I'd like is to extract all the layers, but have them all the same size, so that I can easily lay them on top of each other later, and have everything line up just as it did in the original PSD.

If it helps to visualise it, this is what I'm currently getting with the command above:

+----+
|A   |   +-+   +-+
|    | = |A| + |B|
|   B|   +-+   +-+
+----+

And what I want is:

+----+   +----+   +----+
|A   |   |A   |   |    |
|    | = |    | + |    |
|   B|   |    |   |   B|
+----+   +----+   +----+

With the resulting images having a transparent background so that I can do this:

+----+   +----+ 
|A   |   |A   |+
|    | = |    ||
|   B|   |   B||
+----+   +----+|
          +----+

I'm not in any way tied to ImageMagick, so if there's another (preferably command-line) tool that can achieve this, that's fine.

Answer

killmenow picture killmenow · Sep 14, 2011

I use this command line to do what are describing:

convert.exe <filename>.psd -set dispose Background -coalesce <outfilename>.png